PS: listview中有一些简单使用的适配器,如:SimpleAdapter:构造方法SimpleAdapter(上下文语境,List
如图:
<强> 1,首先写布局文件
强>
activity_layout。xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" match_parent " android: layout_height=癿atch_parent”比; & lt;列表视图 android: layout_width=" match_parent " android: layout_height=" match_parent " android: id=癅 + id/id_lv”比; & lt;/ListView> & lt;/LinearLayout> >之前没一个条目的样式:itemstyle_layout.xml 其中的图片自己随便找个即可。
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android " android: layout_width=" match_parent " 面向android:="水平" android: layout_height=癿atch_parent”比; & lt; ImageView android: layout_width=" 70 dp” android: layout_height=" 80 dp” android: src=" https://www.yisu.com/zixun/@drawable“金银铜/比; LinearLayout & lt; android: layout_width=" 0 dp” android: layout_weight=" 0.9 " android: layout_height=" 80 dp” 面向android:=按怪薄北? & lt; TextView android: layout_width=" match_parent " android: layout_height=" wrap_content " android: textSize=" 35 dp” android:文本=" 11111 " android: id=癅 + id/id_item_tv”/比; & lt; TextView android: layout_marginTop=" 5 dp " android: layout_width=" match_parent " android: layout_height=" wrap_content " android: textSize=" 20 dp” android:文本=" 11111 " android: id=癅 + id/id_item_tv2”/比; & lt;/LinearLayout> LinearLayout & lt; android: layout_width=" 0 dp” android: layout_height=" 80 dp” android: layout_weight=" 0.1 " 面向android:=按怪薄北? & lt; ImageView android: layout_width=" match_parent " android: layout_height=" 50 dp” android: src=" https://www.yisu.com/zixun/@drawable xin1 "/比; & lt;/LinearLayout> & lt;/LinearLayout> >之前<强> 2,创建适配器MyAdapter.java ,>强(已优化)
申明一点,适配中有优化方法,如果不优化的话,有时也可以加载出来,但有时就会加载错乱,没调用一次就会多浪费创建一个视图对象,如:
视图项=LayoutInflater.from(上下文).inflate (R.layout.itemstyle_layout, null);//TextView信息=(TextView) item.findViewById (R.id.id_item_tv);//info.setText (list.get(位置)+ " "); >之前优化后(加入了Viewholder)
公开课MyAdapter延伸BaseAdapter {//公共List