簡體   English   中英

從列表中檢索圖像

[英]Retrieving images from list

我必須存儲圖像並根據響應切換圖像。 例如:

int[] fimg = new int[]{
    R.drawable.apple,
    R.drawable.banana,
    R.drawable.org,
    R.drawable.pgranate,
    R.drawable.melon,
    R.drawable.grapes
};

我使用此方法進行存儲,但是如何檢索?

只需使用:

myImageView.setImageResource(fimg[0]); //0 is the index of your int array

您不是在這里使用列表,而是在使用數組,為了使用列表,請執行以下操作

List<integer> list = new ArrayList<integer>()
  for( String f : fimg ) {
  list.add(f);
}

現在,您只需按以下方式檢索

list.get(position)

(ImageView image = (Imageview) new findViewById(list.get(position));)

它將返回int

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM