将我的drawable文件夹中的图像实现到List

时间:2016-10-13 23:46:32

标签: android

如何实现 - 从我的drawable文件夹中打开图像,而不是打开这些url的图像?我尝试用(“drawable / img.jpg”)替换Url而没有运气。

public void startGalleryActivity() {
    ArrayList<String> images = new ArrayList<String>();
      images.add("http://sourcey.com/images/stock/salvador-dali-persistence-of-memory.jpg");
    images.add("http://sourcey.com/images/stock/salvador-dali-the-dream.jpg");


    Intent intent = new Intent(MainActivity.this, GalleryActivity.class);
    intent.putStringArrayListExtra(GalleryActivity.EXTRA_NAME, images);
    startActivity(intent);
}

1 个答案:

答案 0 :(得分:1)

由于R.drawable值是整数,请使用putIntegerArrayListExtra()

public void startGalleryActivity() {
    ArrayList<Integer> images = new ArrayList<>();
    images.add(R.drawable.image_one);
    images.add(R.drawable.image_two);
    // and so on

    Intent intent = new Intent(MainActivity.this, GalleryActivity.class);
    intent.putIntegerArrayListExtra(GalleryActivity.EXTRA_NAME, images);
    startActivity(intent);
}