GridView gv=(GridView)findViewById(R.id.g1);
ArrayList<HashMap<String,Object>>data=new ArrayList<HashMap<String, Object>>();
for(int i=0;i<images.length;i++)
{
HashMap<String,Object>hash=new HashMap<String, Object>();
hash.put("ItemImage",images[i]);
hash.put("ItemText",imagesName[i]);
data.add(hash);
}
SimpleAdapter simpleAdapter=new SimpleAdapter(this,data,R.layout.item,new String[]{"ItemImage","ItemText"},new int[]{R.id.ItemImage,R.id.ItemText});
gv.setAdapter(simpleAdapter);
//建立图片和图片名字数组:
private final int[] images=new int[]{R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,
R.drawable.e,R.drawable.f,R.drawable.g,R.drawable.h,R.drawable.k};
private final String[] imagesName=new String[]{
"京东","阅读","百度","新浪","当乐","信息","宜搜","未知","淘宝","雅虎","搜狐"
};
GridView实现九宫格
点赞
收藏