首页 > 代码库 > 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 }
View Code

 

Adapter