2012-12-13 54 views
0

在XML中獲取資源ID:從繪製

<ImageButton 
    android:id="@+id/b_checkEv" 
    android:src="@drawable/img_huella" 
    ... /> 

在活動:

 ImageButton ib = (ImageButton) findViewById(R.id.b_checkEv); 
    Drawable dr = ib.getDrawble(); 

我改變dinamically的ImageButton的形象在代碼ib.setDrawable()。 任何人都知道如何從Drawable中獲取資源ID以便知道在每個時刻在ImageButton中設置了哪個圖像?

謝謝!

+5

你可以維護一個int值來保存這個值。恩。 int currentImage = R.drawable.image; ib.setDrawable(currentImage); – dymmeh

+0

它有幫助,謝謝! – user23

回答

0

控制Android按鈕的最佳方式是標籤。

您可以在這裏執行「ib.setTag(」image1.png「)」並管理圖像數據。

然後你可以做「String imageName = ib.getTag()」並獲取圖像名稱。

Regards