Android开发学习笔记:浅谈GridView(7)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:44 点击:次
//图片的文字标题
private String[] titles = new String[]
{ "pic1", "pic2", "pic3", "pic4", "pic5", "pic6", "pic7", "pic8", "pic9"};
//图片ID数组
private int[] images = new int[]{
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.pic9
};
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridview);
PictureAdapter adapter = new PictureAdapter(titles, images, this);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(MainActivity.this, "pic" + (position+1), Toast.LENGTH_SHORT).show();
}
});
}
}
//自定义适配器
class PictureAdapter extends BaseAdapter{
private LayoutInflater inflater;
private List<Picture> pictures;
public PictureAdapter(String[] titles, int[] images, Context context)
{
super();
pictures = new ArrayList<Picture>();
inflater = LayoutInflater.from(context);
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>