public class MainActivity extends Activity {
private GridView gv;
private SimpleAdapter sim_adapter;
private List<Map<String,Object>>dataList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv=(GridView) findViewById(R.id.gridView1);
dataList=new ArrayList<Map<String,Object>>();
sim_adapter=new SimpleAdapter(this, getData(), R.layout.item, new String[]{"img","text"}, new int[]{R.id.imageView1,R.id.textView1});
gv.setAdapter(sim_adapter);
}
private List<Map<String,Object>> getData(){
int[] img=new int[]{R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5};
String[] imgName=new String[]{"图片1","图片2","图片3","图片4","图片5"};
Map<String,Object>map=new HashMap<String, Object>();
for(int i=0;i<=img.length;i++){
map.put("img", img[i]);
map.put("text", imgName[i]);
dataList.add(map);
}
return dataList;
}
}
阿旭_
Mr_QiuL
JustWannaHugU
帅帅嗒先锋
慕粉3853642
皮卡丘qinqin
相关分类