Android with Actionbar Sherlock。 ImageButtonはオンクリックイベントを取得しません
-
29-10-2019 - |
質問
ActionBar Sherlockを使用するAndroidアプリがあります。描画可能なリソースファイルで状態が定義されているImageButtonを備えたメニューを作成します。 (それらのすべてが以下に貼り付けられています)。
Image -Buttonの選択された /非選択されていない状態を切り替えることはできますが、クリックリスナーは発火していないようです。
アクティビティが作成されたら、メニューを膨らませ、ImageButtonを取得し、イベントリスナーを登録します。私はデバッグしました、そしてそれはすべて大丈夫のようです(私は正しいImageButtonでイベントを登録しています)。
ImageButtonがOnClickコールバックを取得しないようにする可能性があると思いますか?
乾杯....
ここにいくつかのコードがあります:
メニュー:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_save"
android:showAsAction="always|withText"
android:actionLayout="@layout/menu_my_activity"
/>
</menu>
menu_my_activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_with_states"
android:clickable="true" />
</LinearLayout>
そしてリスナーの登録:
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = (MenuInflater) this.getMenuInflater();
inflater.inflate(R.menu.menu_watchlist, menu);
menu.getItem(0).getActionView().findViewById(R.id.imageButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Test", "Hello");
}
});
return super.onCreateOptionsMenu(menu);
}
正しい解決策はありません
所属していません StackOverflow