鹿鼎记陈小春版演员表,数字家电,清野静流
android ui:listview -- simpleadapter
simpleadapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便。
layout :
<?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="horizontal"> <listview android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#7f00" //分割线 android:dividerheight="2dp" android:id="@+id/listview_sample"/> </linearlayout>
header layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <imageview android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> </linearlayout>
自定义布局 item:
<?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="horizontal"> <imageview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3px" android:id="@+id/img"/> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:textsize="16sp" android:id="@+id/title"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/info" android:textsize="16sp"/> </linearlayout> </linearlayout>
java 代码:
public class sampleadapteractivity extends activity { private listview mlistview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.sampleadapter_layout); mlistview = (listview) findviewbyid(r.id.listview_sample); simpleadapter adapter = new simpleadapter(this, getdata(), //数据来源 r.layout.item_listview, //对应item view new string[]{"img","title","info"}, //data 中对应值 new int[]{r.id.img,r.id.title,r.id.info}); //填充layout位置 mlistview.setheaderdividersenabled(true); //是否显示头view 的分割线 view header = view.inflate(this,r.layout.listview_header,null); view footer = view.inflate(this,r.layout.listview_header,null); mlistview.addheaderview(header); //添加头部view mlistview.addfooterview(footer); //添加底部view mlistview.setadapter(adapter); } @override protected void onresume() { super.onresume(); } private list<? extends map<string,?>> getdata() { list<map<string,object>> items = new arraylist<map<string, object>>(); for (int i = 0; i < 5; i++) { map<string,object> item = new hashmap<string,object>(); item.put("img",r.mipmap.ic_launcher); item.put("title","title -- " + i ); item.put("info","info -- " + i ); items.add(item); } return items; } }
显示效果
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android Manifest中meta-data扩展元素数据的配置与获取方式
Android实现获取meta-data和build.gradle的值
Android获取清单文件中的meta-data,解决碰到数值为null的问题
解决webview 第二次调用loadUrl页面不刷新的问题
解决Android WebView拦截url,视频播放加载失败的问题
Android webview加载https链接错误或无响应的解决
网友评论