为什么我设置了四张图片,可是显示的时候是八张?
public class MainActivity extends Activity {
private GridView gridView;
private List<Map<String, Object>> dataList;
private int[] icon = { R.drawable.kaier, R.drawable.timo,
R.drawable.xinxaing,R.drawable.h };
private String[] iconName = { "凯尔", "提莫", "信箱","樱花" };
private SimpleAdapter adapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.grideview);
// 1、准备数据源
// 2、新建适配器(SimpleAdapter)
// 3、GridView加载适配器
// 4、GridView配置事件监听器(OnItemClickListener)
dataList = new ArrayList<Map<String, Object>>();
getData();
adapter = new SimpleAdapter(this, getData(), R.layout.item,
new String[] { "image", "text" }, new int[] { R.id.image,
R.id.text });
gridView.setAdapter(adapter);
}
private List<Map<String, Object>> getData() {
for(int i=0;i<4;i++)
{
Map<String,Object>map=new HashMap<String, Object>();
map.put("image",icon[i]);
map.put("text", iconName[i]);
dataList.add(map);
}
return dataList;
// TODO 自动生成的方法存根
}
}