首页 > 移动平台 > 详细

Android ListView实现任意layout

时间:2014-10-17 02:38:45      阅读:288      评论:0      收藏:0      [点我收藏+]
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
				R.layout.timenotes_item_left, new String[] { "text1", "text2",
						"text3" }, new int[] { R.id.textView2, R.id.textView3,
						R.id.textView4 }) {
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				Map itemData = (Map) getItem(position);
				int type = Integer.parseInt(itemData.get("type").toString());
				View itemView = null;
				switch (type) {
				case 0:
					Log.d("adapter", "type 0");
					itemView = View.inflate(getApplicationContext(),
							R.layout.timenotes_item_left, null);
					break;
				case 1:
					Log.d("adapter", "type 1");
					itemView = View.inflate(getApplicationContext(),
							R.layout.timenotes_item_right, null);
					break;
				default:
					Log.d("adapter", "type default");
					break;
				}
				return itemView;
			}
		};
		ListView listView = (ListView) findViewById(R.id.listView1);
		listView.setAdapter(adapter);


Android ListView实现任意layout

原文:http://my.oschina.net/lovelyBoy/blog/333064

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!