设置动态图像形式位图

时间:2015-04-10 15:19:42

标签: android bitmap imageview

我有一个问题。我是Android新手 我的程序在网格视图中设置图像。从列表中获取名称并转到资产文件夹并显示图片。我想要从drawable显示图片,但我不能。我的类是扩展ArrayAdapter

ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);

    try { BitmapFactory.decodeStream(context.getAssets().open(items.get(position).uri));
        imageView.setImageBitmap(bitmap);       
    } catch (IOException e) {
        e.printStackTrace();
    }

我需要从列表中获取名称图片并转到drawable并在imageview中显示 感谢

1 个答案:

答案 0 :(得分:1)

你需要像这样创建一个可绘制的Integer数组:

    private Integer[] drawbleArray = {R.drawable.image1, R.drawable.image2, R.drawable.image3};

将此数组作为构造函数中的参数传递给适配器,您可以像这样设置图像:

imageView.setImageResource(drawbleArray[i]);
相关问题