常见数据适配器

常见数据适配器

  • ArrayAdapter 数组适配器

    java代码:(要记得声明ListView控件)
    
    String[] objects = new String[]{"app","context","Media","nfc","os"}
    lv.setAdapter(new ArrayAdapter(this,R.layout.item,objects));
    
    Android代码: 
    
    
    
    

  • SimpleAdapter 简单数据适配器

  • java代码:(要记得声明ListView控件)
    
    List> data= new                            ArrayList>();
          Map map1 = new HashMap();
          map1.put("icon",R.drawable.ic_launcher);
          map1.put("name", "功能设置");
          data.add(map1);
          Map map2 = new HashMap();
          map2.put("icon",R.drawable.ic_tupian);
          map2.put("name", "qita设置");
          data.add(map2);
      lv.setAdapter(newSimpleAdapter(this,data,R.layout.item, new String[]{"icon","name"}, new int[]{R.id.iv,R.id.tv}));
      
    Android代码: 
    
    
        
        
    
    

你可能感兴趣的:(常见数据适配器)