0

私は次のImageButtonような子xmlレイアウトを持っています:

<ImageButton 
    android:id="@+id/favoriteButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/citrus_orange"
    android:paddingLeft="@dimen/feed_item_padding_left_right"
    android:background="@null"
    andorid:onClick="flipVote"/>

アダプターでこのボタンをプログラムでフォーカス不可にします。

ImageButton favButton = (ImageButton) convertView.findViewById(R.id.favoriteButton);

favButton.setFocusable(false);

同じレイアウトで、次のTextViewようなものがあります。

<TextView
     android:id="@+id/store_id"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:visibility="gone" />

クリックするとflipVote(View view)メソッドが呼び出されます。

public void flipVote(View view) {
        // make a network call with the value from store_id
     }

TextViewクリックされたボタンに関連付けられたから値を取得して、ネットワーク呼び出しに含めるにはどうすればよいですか?

4

2 に答える 2

0

これを実現する適切な方法は、タグを使用することであることがわかりました。私はそれを次のようにしました:

アダプタ

// store is data model
favButton.setTag(store.getId());

アクティビティ

// use it in the flipVote(View view) method
public void flipVote(View view) {
        JSONObject storeVoteData = new JSONObject();

try {
    storeVoteData.put("store_id", view.getTag());
    } catch (JSONException e) {
             e.printStackTrace();
         }
     }

  // make Volley call with JSONObject
}
于 2014-07-24T19:42:30.090 に答える
0

アダプターでは、ボタンのクリックをインターセプトし、リスナーで TextView.getText を作成してから、メソッド FlipVote を値で呼び出す必要があります。

于 2014-07-23T22:17:14.910 に答える