Adapter

来源:互联网 发布:java 滑动验证码 开源 编辑:程序博客网 时间:2024/05/18 00:01

SimpleAdapter Demo:


<span style="font-size:14px;">public class SimpleAdapterDemo extends Activity{private SimpleAdapter simpleAdapter;private ArrayList<HashMap<String, Object>> dataList;private ListView lv;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.arrayadapter);lv = (ListView) findViewById(R.id.lv);HashMap<String, Object> map;dataList = new ArrayList<HashMap<String, Object>>();String[] text = new String[] { "first1", "second1", "third1" };String[] text2 = new String[] { "first2", "second2", "third2" };int[] resourceId = new int[] { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher };for (int i = 0; i < 3; i++) {map = new HashMap<String, Object>();map.put("img", resourceId[i]);map.put("text1", text[i]);map.put("text2", text2[i]);dataList.add(map);}String[] key = new String[] { "img", "text1", "text2"};int[] id = new int[] { R.id.img, R.id.text1, R.id.text2 };simpleAdapter = new SimpleAdapter(this, dataList, R.layout.simple, key, id);lv.setAdapter(simpleAdapter);}}</span><span style="color:#ff0000;"></span>


0 0
原创粉丝点击