私はいくつかのImageButtonをプログラムでTableLayoutに配置してきましたが、すべてのImageButtonには独自のDrawableリソースが背景としてあります。ImageButton自体のレイアウトにXML記述を使用し、その後、LayoutInflaterを使用してそのようなImageButton(genre_cell.xmlと呼ばれる)を取得します。
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/genreCellItemId" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="5dip" android:paddingRight="5dip">
</ImageButton>
そして私のクラスでは私はします:
myButton = (ImageButton) inflater.inflate(R.layout.genre_cell, row, false);
実際にすべてのImageButtonにonClickListenerをアタッチしましたが、クリックされたImageButtonを一意に識別したいと思います...背景に使用されているDrawableのIDを取得して、使用可能なDrawableのIDで確認できるのではないかと思いました。 int値?これはオプションですか?もしそうなら、どのように実装する必要がありますか?他にオプションはありますか?