使用drawable将图像添加到gridview

时间:2016-05-21 23:45:01

标签: java android gridview layout

如何从drawable和to将图像添加到gridview 如果我选择在arraylist

中存储位置所需的图像,我也需要图像的复选框

2 个答案:

答案 0 :(得分:0)

试试这个..它对我有用

private ArrayList<Integer> Gallery_Images = new ArrayList<Integer>();

 Resources resources = getResources();
 Gallery_Images.add(R.drawable.gallery_img_one);
 Gallery_Images.add(R.drawable.gallery_img_two);
 Gallery_Images.add(R.drawable.gallery_img_three);
 Gallery_Images.add(R.drawable.gallery_img_four);
 Gallery_Images.add(R.drawable.gallery_img_five);
 Gallery_Images.add(R.drawable.gallery_img_six);
 gridView.setAdapter(new Image_Custom_Adapter(this, Gallery_Images));

答案 1 :(得分:0)

您需要创建一个图像数组并将其链接到gridview适配器,如此

int[] images = {R.drawable.one,R.drawable.two,
        R.drawable.three,R.drawable.four, R.drawable.five,
        R.drawable.six,R.drawable.seven,R.drawable.eight,
        R.drawable.nine};

然后

 GridViewAdapter adapter =
        new GridViewAdapter(MainActivity.this, num, images);

详细信息请访问此链接

http://androidcoding.in/2016/05/17/android-tutorial-on-grid-view/