我想在我的android應用程序中使圖像動態。隨着其他職位的幫助我寫了這段代碼,但我無法設置圖像資源。這是我的代碼。動態圖像源android
// get image whose source i want to change..
ImageView IV = (ImageView) findViewById(R.id.imageView1);
// x for 1,2,3.. hangman1.png,hangman2.png and so on image are located
// under res/drawable-mdpi
int j = getResources().getIdentifier("hangman"+x, "imageView", getPackageName());
// here i get errork, The method setImageResource(int) in the type ImageView
// is not applicable for the arguments (Drawable)
IV.setImageResource(getResources().getDrawable(j));
是,您需要指定資源的類型。像在'R.drawable.hangman1'中一樣:類型是'drawable'而不是'imageView'。 – Peterdk