码迷,mamicode.com
首页 > 其他好文 > 详细

Adapter

时间:2014-12-26 14:35:09      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

SimpleAdapter Demo:

技术分享
 1 public class SimpleAdapterDemo extends Activity{
 2     private SimpleAdapter simpleAdapter;
 3     private ArrayList<HashMap<String, Object>> dataList;
 4     private ListView lv;
 5     @Override
 6     protected void onCreate(Bundle savedInstanceState) {
 7         // TODO Auto-generated method stub
 8         super.onCreate(savedInstanceState);
 9         setContentView(R.layout.arrayadapter);
10         lv = (ListView) findViewById(R.id.lv);
11         HashMap<String, Object> map;
12         dataList = new ArrayList<HashMap<String, Object>>();
13         String[] text = new String[] { "first1", "second1", "third1" };
14         String[] text2 = new String[] { "first2", "second2", "third2" };
15         int[] resourceId = new int[] { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher };
16         
17         for (int i = 0; i < 3; i++) {
18             map = new HashMap<String, Object>();
19             map.put("img", resourceId[i]);
20             map.put("text1", text[i]);
21             map.put("text2", text2[i]);
22             dataList.add(map);
23         }
24         
25         String[] key = new String[] { "img", "text1", "text2"};
26         int[] id = new int[] { R.id.img, R.id.text1, R.id.text2 };
27         simpleAdapter = new SimpleAdapter(this, dataList, R.layout.simple, key, id);
28         lv.setAdapter(simpleAdapter);
29     }
30     
31 }
View Code

 

Adapter

标签:

原文地址:http://www.cnblogs.com/coolguy/p/4186533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!