首页 > 其他 > 详细

Adapter

时间:2014-12-26 14:32:05      阅读:151      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!