Home > Mobile >  ImageView unable to display images in SimpleAdapter
ImageView unable to display images in SimpleAdapter

Time:05-25

XML list_item.
 & lt; ? The XML version="1.0" encoding="utf-8"?> 
Android: layout_width="match_parent"
Android: layout_height="match_parent"
The android: orientation="horizontal" & gt;
The android: id="@ + id/imgtou"
Android: layout_width="64 dp"
Android: layout_height="64 dp"
Android: baselineAlignBottom="true"
Android: paddingLeft="8 dp"/& gt;

Android: layout_width="match_parent"
Android: layout_height="wrap_content"
Android: orientation="vertical" & gt;

The android: id="@ + id/name"
Android: layout_width="wrap_content"
Android: layout_height="wrap_content"
Android: paddingLeft="8 dp"
Android: textColor="# 1 d1d1c"
Android: textSize="20 sp/& gt;"

The android: id="@ + id/says"
Android: layout_width="wrap_content"
Android: layout_height="wrap_content"
Android: paddingLeft="8 px"
Android: textColor="# B4B4B9"
Android: textSize="14 sp/& gt;"



MainActivity. Java
 public class MainActivity extends AppCompatActivity {
Private String [] names=new String [] {god "B", "base" god, "god cao"};
Private String [] saith=new String [] {" intangible is black, the most lethal, "" great god so much ~", "I will take the lead, the dog ~"};
Private int [] imgIds=new int [] {R.m ipmap. Head_icon1, R.m. Ipmap head_icon2, R.m ipmap. Head_icon3};

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

List Listitem=new ArrayList (a);
for (int i=0; I & lt; Names. Length; I++) {
Map Showitem=new HashMap (a);
Showitem. Put (" touxiang imgIds [I]);
Showitem. Put (" name ", names [I]);
Showitem. Put (" says, "says [I]);
Listitem. Add (showitem);
}

//create a simpleAdapter
SimpleAdapter myAdapter=new SimpleAdapter (getApplicationContext (), listitem, R.l ayout. List_item, new String [] {" touxiang ", "name", "says"}, new int [] {R.i d.i mgtou, R.i d.n ame, R.i d.s ays});
ListView ListView=(ListView) the findViewById (R.i d.l ist_test);
ListView. SetAdapter (myAdapter);

}
}


  • Related