ListView的使用
来源:互联网 发布:蝎子网络第二季5 编辑:程序博客网 时间:2024/06/06 01:04
熟练运用两种适配器 ArrayAdapter,SimpleAdapter
学会熟练运用两种监听器OnScrollListener,OnItemClickListener
学会熟练运用适配器数据的刷新 notifyDataChanged
ArrayAdapter使用
private ListView listView;private ArrayAdapter<String> arr_adatapter;<pre name="code" class="java">listView=(ListView) findViewById(R.id.listView); //新建一个适配器 //ArrayAdapter(上下文,当前listView每个项加载的布局文件(这里使用自带的布局文件),数据源) //适配器加载数据源 String [] arr_data={"慕课网","麦子学院",""}; arr_adatapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arr_data); listView.setAdapter(arr_adatapter);
SimpleAdapter使用
创建item.xml文件
<?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" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:src="@drawable/abc_ab_bottom_solid_dark_holo" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="14sp" android:textColor="#000000" android:text="demo" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="14sp" android:textColor="#000000" android:text="demo" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/imgx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="15dp" android:src="@drawable/abc_ab_bottom_solid_dark_holo" /> </LinearLayout></LinearLayout>
private SimpleAdapter simp_adapter;private List<Map<String,Object>> datalist;
//context:上下文 //data:数据源(List<? extends Map<String,?>> data) 一个Map所组成的list集合) 每一个Map都会去对应listView列表中的一行 每一个map都是由键值对组成 必须去包含所有from中所有指定键 //resource:列表项的布局文件id //from:Mpa中的键名 //to:绑定数据视图中的id 与from对应 datalist=new ArrayList<Map<String,Object>>(); simp_adapter=new SimpleAdapter(this, getDate(), R.layout.item, new String []{"img","imgx","title","text"}, new int[]{R.id.img,R.id.imgx,R.id.title,R.id.text}); listView.setAdapter(simp_adapter);
private List<Map<String,Object>> getDate(){ for (int i = 0; i < 20; i++) {Map<String,Object> map=new HashMap<String, Object>();map.put("img", "img"+i);map.put("imgx", "imgx"+i);map.put("title", "title"+i);map.put("text", "text"+i);datalist.add(map);} return datalist; }
0 0
- listview 的使用
- ListView的使用
- ListView的使用技巧
- delphi ListView 的使用
- ListView的使用
- EasyMF ListView 的使用
- ListView的使用
- listview的使用1
- ListView的使用
- ListView控件的使用
- ListView的使用
- Listview 的基本使用
- ListView的使用1
- ListView的使用2
- android ListView的使用
- listView的使用
- VB ListView的使用
- ListView 控件的使用
- Android 探究 LayoutInflater setFactory文章的补充
- Ubuntu 14.04编译RT288x_SDK/toolchain/squashfs3.2-r2时出错
- TabHost控件应用
- 判断手机号的输入是否正确、获取当前的时间以及显示距离上次发布有多久的时间
- IOS开发 Xcode7.3不能提示自定义类名问题解决办法
- ListView的使用
- Lua内存泄露情况举例
- Qt Creator中添加菜单栏实例
- 第一个程序
- cell 的自带的系统方法
- 使用百度sdk简单定位
- Log,Toast,SPUtil,Density,SDCard,ScreenUtil,AppVersion,KeyBoard,NetWork,HttpUtil工具类
- Java利用反射实现对象转json
- leetcode 66 Plus One C++