Android Study,ListView升级使用,支持图片等展现
1、实现ListView布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/lsvShow" android:layout_width="wrap_content" android:layout_height="wrap_content" > </ListView> </LinearLayout>
2、实现ListView的Item布局,支持图片等展现
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="horizontal" > 6 7 <ImageView 8 android:id="@+id/icon" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" /> 11 12 <TextView 13 android:id="@+id/name" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" /> 16 17 <TextView 18 android:id="@+id/info" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" /> 21 22 <CheckBox 23 android:id="@+id/check" 24 android:layout_width="wrap_content" 25 android:layout_height="wrap_content" /> 26 27 </LinearLayout>
3、实现展现逻辑
1 public class ListViewActivity extends Activity { 2 3 private ListView _lsvShow; 4 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 // TODO Auto-generated method stub 8 super.onCreate(savedInstanceState); 9 10 setContentView(R.layout.view_listview); 11 12 _lsvShow = (ListView) findViewById(R.id.lsvShow); 13 14 generatorImageItem(); 15 } 16 17 private void generatorImageItem() { 18 19 ArrayList<HashMap<String, Object>> dataSource = new ArrayList<HashMap<String, Object>>(); 20 for (int i = 0; i < 10; i++) { 21 22 HashMap<String, Object> hashMap = new HashMap<String, Object>(); 23 hashMap.put("icon", R.drawable.ic_launcher); 24 hashMap.put("name", "小伙伴" + i); 25 hashMap.put("info", ",小伙伴们都惊呆了!"); 26 dataSource.add(hashMap); 27 } 28 29 SimpleAdapter adapter = new SimpleAdapter(this, dataSource, 30 R.layout.body_listview_image_item, new String[] { "icon", 31 "name", "info" }, new int[] { R.id.icon, R.id.name, 32 R.id.info }); 33 34 _lsvShow.setAdapter(adapter); 35 }
实现展现效果


浙公网安备 33010602011771号