有點奇怪的問題:如何檢查ImageView(在android中)當前在屏幕上顯示的照片?
是否有可能找回id或/和在ImageView中的活動資源的名稱?這是代碼。
ImageView photo = (ImageView) findViewById(R.id.placeForPhoto);
//here I choose random photo from drawable (photo 1 to photo 10)
//and then I show it on the screen as below
photo.setImageResource(R.drawable.photo1); //or photo2 or photo3 or...
在代碼的其他部分,我想檢查哪張照片是Atm在placeForPhoto中呈現。如果是R.drawable.photo1或R.drawable.photo2或...
所以我需要的只是不便喜歡有可能達到這樣的比較:
if ([presented atm photo in ImagView photo] == R.drawable.photo1)
{do something}
else if ([presented atm photo in ImagView photo] == R.drawable.photo2)
{do smth different}
else {...}
我想: photo.getID(),但它返回placeForPhoto的ID而不是內部的資源;
photo.getResource(),但它返回比照片
的getResource()的ID不同的一些其它值。則getIdentifier(),但它給ID時,你有名字,我沒有名字(或也許有可能從ImageView照片獲取名稱?)
getResources()。getResourceName()但是我必須有我正在尋找的id。
Thx提前。
Thx。我正在考慮使用標籤,所以如果imageview中沒有資源ID,我會爲他們做。 – Michal