基本按照老师步骤编写,却运行不了。求高人指点!!!
public class MainActivity extends Activity {
GridView gv;
SimpleAdapter sa;
List<HashMap<String, Object>> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gv=(GridView) findViewById(R.id.gridView1);
//创建数据源
list=new ArrayList<HashMap<String,Object>>();
//适配器
sa=new SimpleAdapter(this, getData(), R.layout.main,
new String[]{"imageView1","textView1"}, new int[]{R.id.imageView1,R.id.textView1} );
//添加适配器
gv.setAdapter(sa);
}
//给list赋值
public List<HashMap<String, Object>> getData(){
for(int i=0;i<7;i++){
HashMap<String, Object>map=new HashMap<String, Object>();
map.put("imageView1", R.drawable.ic_launcher);
map.put("textView1", "hao"+i);
}
return list;
}
}