网站大量收购独家精品文档,联系QQ:2885784924

020702列表显示ListView.ppt

  1. 1、本文档共37页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
如果现在希望可以显示更加丰富的效果,则就需要使用SimpleAdapter类完成操作了,SimpleAdapter类的继承结构如下所示: java.lang.Object ? android.widget.BaseAdapter ? android.widget.SimpleAdapter SimpleAdapter类的主要功能是将List集合的数据转换为ListView可以支持的数据,而要想实现这种转换,首先需要定义一个数据的显示模板(专门定义一个布局管理器,基本上都是表格布局),在这一模板中可以定义ListView每一行所需要显示的所有组件,而在需要转换的List集合里保存的是多条Map集合的数据,这些Map集合里面保存着一些具体的要显示的信息,即:模板中每一个组件的ID实际上就相当于规定了里面保存的Map集合的key,而模板中每个组件的显示内容,则由Map保存的value决定。 No. 方法 类型 描述 1 public SimpleAdapter (Context context, List? extends MapString, ? data, int resource, String[] from, int[] to) 构造 创建SimpleAdapter对象,需要传递Context对象,封装的List集合,要使用的布局文件ID,需要显示的key(对应Map)、组件的id。 2 public int getCount() 普通 得到保存集合的个数 3 public Object getItem(int position) 普通 取得指定位置的对象 4 public long getItemId(int position) 普通 取得指定位置对象的ID 5 public void notifyDataSetChanged() 普通 当列表项发生改变时,通知更新显示ListView ?xml version=1.0 encoding=utf-8? TableLayout ? 定义表格布局 xmlns:android=/apk/res/android android:layout_width=fill_parent ? 布局管理器宽度为屏幕宽度 android:layout_height=wrap_content ? 布局管理器高度为文字高度 TableRow ? 定义表格行 ImageView ? 定义图片显示组件 android:id=@+id/icon” ? 组件ID,程序中使用 android:layout_height=wrap_content”? 组件高度为图片宽度 android:layout_width=wrap_content”? 组件宽度为图片高度 android:src=@drawable/file_icon/? 组件显示图片 TextView ? 定义文本显示组件 android:id=@+id/_id“ ? 组件ID,程序中使用 android:textSize=6px” ? 文字大小为6像素 android:gravity=center_vertical” ?显示内容垂直居中 android:layout_height=wrap_content”? 组件高度为文字高度 android:layout_width=wrap_content/? 组件宽度为文字宽度 TextView ? 定义文本显示组件 android:id=@+id/name“ ? 组件ID,程序中使用 android:textSize=6px“ ? 文字大小为6像素 android:gravity=center_vertical” ?显示内容垂直居中 android:layout_height=wrap_content”? 组件高度为文字高度 android:layout_width=wrap_content/? 组件宽度为文字宽度 /TableRow /TableLayout ?xml version=1.0 encoding=utf-8? LinearLayout ? 定义线型布局 xmlns:android=/apk/res/android android:orientation=vertical ? 所有组件垂直摆放 android:layout_width=fill_parent“ ? 布局管理器宽度为屏幕宽度 android:layout_height=fill_parent ? 布局管理器高度为屏幕高度 TextView ?

文档评论(0)

wx171113 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档