欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中的Adapter簡單介紹

 更新時間:2013年06月02日 15:19:38   作者:  
Android中的Adapter簡單介紹,需要的朋友可以參考一下
Android中的Adapter在自定義顯示列表時非常有用,比如SimpleAdapter,它的構(gòu)造函數(shù)是:
  public SimpleAdapter (Context context, List> data, int resource, String[] from, int[] to)
  它的各參數(shù)的意思:
  1.context,上下文,SimpleAdapter關(guān)聯(lián)的視圖,一般而言就是當前的Activity,this
  2.data,泛型的List,如ArrayList,Map或者HashMap
  3.resource,資源文件,一個R.layout,就是要顯示的布局
  4.from ,一個數(shù)組,Map中的鍵值對。
  5.to,layout的xml文件中命名id形成的唯一的int型標識符
  比如:
  在一個ListActivity中定義一個List:
  List> people= new ArrayList>();
  Map m=new HashMap();
  m.put("name","tom");
  m.put("age","20");
  people.add(m);
  ...
  SimpleAdapter adapter = new SimpleAdapter(this,
  (List>) feets, R.layout.main,
  new String[] { "name","age" }, new int[] {R.id.name,R.id.age });
  setListAdapter(adapter);
  其中:
  R.id.name,R.id.age 是在一個XML布局文件中定義的兩個用于顯示name和age的TextView。布局文件中要有一個ListView?;蛘咴诔绦蛑卸x也可以。
  另外,注意在ListActivity中不需要設(shè)置setContentView,系統(tǒng)被自動加載。

相關(guān)文章

最新評論