首页 > 移动平台 > 详细

Android的适配器

时间:2016-02-24 09:31:30      阅读:241      评论:0      收藏:0      [点我收藏+]

//====================ArrayAdapter===================================

public class List1 extends  Activity {  
   
    private ListVeiw listView;  
    @Override 
    public void onCreate(Bundle savedInstanceState) {  
   super.onCreate(savedInstanceState);  
   
       listView=new ListVeiw(this);  
       listView.setAdapter(new ArrayAdapter<String>(this,  
           android.R.layout.simple_list_item_1, mStrings));  
      setContentVieww(listView);  
        }  
   
   private String[] mStrings = {  
           "Abbaye de Belloc", "Abbaye du Mont des Cats",      
           "Acorn", "Adelost", "Affidelice au Chablis",   
           "Aisy Cendre", "Allgauer Emmentaler", "Alverca",   
           "Ami du Chambertin", "Anejo Enchilado", "Anneau   
           "Aragon", "Ardi Gasna", "Ardrahan", "Armenian   
           "Asadero", "Asiago", "Aubisque Pyrenees", "Autun",   
            "Babybel", "Baguette Laonnaise", "Bakers", "Bal"};  

 

 

//=============================SimpleAdapter==========================

public class List3 extends ListActivity {  
      
    List<Map<String, Object>> list;  
   
    @Override 
    public void onCreate(Bundle savedInstanceState) {  
       super.onCreate(savedInstanceState);  
         
       list = getListForSimpleAdapter(); //list为数据集合
   
       SimpleAdapter     adapter = new SimpleAdapter(this, list,  
R.layout.item,  
       new String[] { "BigText", "LittleText", "img" },   
new int[] { R.id.BigText,R.id.LittleText, R.id.img }); 

        //可以想成把一个放好数据的布局文件放入本界面中  
       setListAdapter(adapter);      
   
    }  
   
    private List<Map<String, Object>> getListForSimpleAdapter() {  
    List<Map<String,Object>> list=newArrayList<Map<String,        Object>>(3);  
           Map<String, Object> map = new HashMap<String, Object>();  
           map.put("BigText", "Android");  
           map.put("LittleText", "Google phone.");  
           map.put("img", R.drawable.n);  
           list.add(map);  
   
           map = new HashMap<String, Object>();  
           map.put("BigText", "Lenovo");  
           map.put("LittleText", "Ophone");  
           map.put("img", R.drawable.o);  
           list.add(map);  
   
           map = new HashMap<String, Object>();  
           map.put("BigText", "Droid");  
           map.put("LittleText", "Motorola");  
           map.put("img", R.drawable.droid);  
           list.add(map);  
   
         
       return list;  
    }  
}  

 

Android的适配器

原文:http://www.cnblogs.com/jsonfan/p/5211806.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!