Android开发学习笔记:浅谈GridView(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:44 点击:次
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gv = (GridView)findViewById(R.id.GridView1);
//为GridView设置适配器
gv.setAdapter(new MyAdapter(this));
//注册监听事件
gv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(MainActivity.this, "pic" + position, Toast.LENGTH_SHORT).show();
}
});
}
}
//自定义适配器
class MyAdapter extends BaseAdapter{
//上下文对象
private Context context;
//图片数组
private Integer[] imgs = {
R.drawable.pic0, R.drawable.pic1, R.drawable.pic2,
R.drawable.pic3, R.drawable.pic4, R.drawable.pic5,
R.drawable.pic6, R.drawable.pic7, R.drawable.pic8,
R.drawable.pic0, R.drawable.pic1, R.drawable.pic2,
R.drawable.pic3, R.drawable.pic4, R.drawable.pic5,
R.drawable.pic6, R.drawable.pic7, R.drawable.pic8,
};
MyAdapter(Context context){
this.context = context;
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>