我嘗試訪問,我把在HashMap對象 這是我的相關代碼繪製資源:如何訪問繪製對在HashMap中
private void pairImagesCollection() {
mImages.put(R.drawable.img1, R.drawable.img1shadow);
mImages.put(R.drawable.img2, R.drawable.img2shadow);
mImages.put(R.drawable.img3, R.drawable.img3shadow);
mImages.put(R.drawable.img4, R.drawable.img4shadow);
}
private void checkMatch(View dragView, View view) {
ImageView target = (ImageView) view;
ImageView dragged = (ImageView) dragView;
Drawable image = dragged.getDrawable();
int imgId = mImages.get(Integer.valueOf(image)); // wrong, I don't know how to do it ?!
target.setImageResource(imgId);
}
任何幫助將評價!
爲什麼你要通過'dra wable'對象到'valueOf()',它接受'String'將它轉換爲'int'? – Prashant
@Prashant不,沒有字符串,我認爲R.drawable是獨一無二的,我可以通過imageview檢索所需的圖像 – yaffa