求教 加粗处代码报错一直没找到原因???
package com.imoc.demo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 学习gridview制作二位布局界面
* 数据源-适配器-视图界面
* 集合 simadapter gridview
*/
public class MainActivity extends AppCompatActivity {
private GridView gridView;
private java.util.List<Map<String,Object>> dataList;
private int[]icon ={R.drawable.address_book,R.drawable.calendar,
R.drawable.camera,R.drawable.clock,R.drawable.games_control,
R.drawable.messenger, R.drawable.rightone,R.drawable.settings,
R.drawable.weather,R.drawable.world,R.drawable.yutube};
private String[] iconName={"通讯录","日历","照相机","时钟","游戏",
"短信","铃声","设置","天气","浏览器","视频"};
private SimpleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView=(GridView) findViewById(R.id.gridView);
/**
* 准备数据源
* 新建适配器 simpadapter
* Gridview加载适配器
* gridview配置事件监听器 onitemcliklistener
*/
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);//加载适配器
}
privte List<Map<String,Object>> getData(){
for (int i=0;i<icon.length;i++){
Map<String,Object>map= new HashMap<String, Object>();
map.put("image",icon[i]);
map.put("text",iconName[i]);
dataList.add(map);
}
return dataList;
}