首页 > 代码库 > Adapter
Adapter
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 }
Adapter
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。