SimpleAdapter Demo:
<span style="font-size:14px;">public class SimpleAdapterDemo extends Activity{
private SimpleAdapter simpleAdapter;
private ArrayList<HashMap<String, Object>> dataList;
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.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>