基础课程 PPT Android模块二--界面设计2.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Adroid移动开发 模块二:用户界面设计 .将数据源放入到一个List集合中 ArrayListMapString,Object listItems = new ArrayListMapString,Object(); for(int i=0; inames.length;i++){ MapString,Object listItem = new HashMapString,Object(); listItem.put(kheader, imageIds[i]); listItem.put(kname, names[i]); listItems.add(listItem); } 建立list.xml item.xml---列表单项的布局 Adroid移动开发 模块二:用户界面设计 2.定义适配器对象 SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, //数据源----Map列表 R.layout.item, //行布局 new String[]{kheader,kname}, //数据源字段属性 new int[]{R.id.header,R.}); //布局控件对应id 3.设置适配器 list.setListAdapter(simpleAdapter); 4.进行事件处理 list.setOnItemClickLister() Adroid移动开发 模块二:用户界面设计 自定义适配器结构 与simpleAdapter思路差不多 关键在自定义适配器类的定义 Class MyAdapter extends BaseAdapter { public BordListAdapter (){} public int getCount() {}//数据项个数或列表项行数 public Object getItem(int position) {} public long getItemId(int position) {} public View getView(int position, View convertView, ViewGroup parent) {}//数据项放置到列表项 } Adroid移动开发 模块二:用户界面设计 public View getView(int position, View convertView, ViewGroup parent) { if(convertView==null){ //初始界面 //生成条目界面对象 convertView = inflater.inflate(resource, null); //见后面LayoutInflater 补充知识 nameView = (TextView) convertView.findViewById(R.); } nameView.setText(...); return convertView; } Adroid移动开发 模块二:用户界面设计 LayoutInflater 补充 它的作用类似于 findViewById(), 不同点: LayoutInflater将layout的xml布局文件实例化为View类对象(用来找layout下xml布局文件,并且实例化)!有需要时再用setContentView(view)显示出来。 findViewById()是找具体xml下的具体 widget控件(如:Button,TextView等) Adroid移动开发 模块二:用户界面设计 三种用法 LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.main, null); LayoutInflater inflater = LayoutInflater.from(context); (该方法实质就是第一种方法,可参考源代码) View layout = inflater.inflate(R.layout.main, null); LayoutInflater inflater = getLayoutInflater();(在Ac

文档评论(0)

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

大部分文档都有全套资料,如需打包优惠下载,请留言联系。 所有资料均来源于互联网公开下载资源,如有侵权,请联系管理员及时删除。

1亿VIP精品文档

相关文档