フラグメントを使用して、いくつかの画像を含む GridView と、新しい画像を追加するためのボタンを表示しています。GridView は正常に動作しますが、ボタンの onClick メソッドは呼び出されません。
これは私のフラグメントの onCreateView メソッドです:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_picture_grid_view, container, false);
addPictureButton = (Button) rootView.findViewById(R.id.fragment_grid_view_add_button);
addPictureButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CameraOrAlbumDialogFragment dialogFragment = new CameraOrAlbumDialogFragment();
dialogFragment.show(mContext.getSupportFragmentManager(), "CameraPicker");
}
});
imageGridView = (GridView) rootView.findViewById(R.id.fragment_grid_view);
imageGridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
}
私のonActivityCreatedメソッドでは、GridViewのすべてのアダプターを実行し、正常に動作し、クリックとロングクリックをキャプチャできます。機能しないのは、Button の onCLick メソッドだけです。タッチするとボタン アイコンが変化するのがわかりますが、onClickListener メソッド内の関数は呼び出されません。何か助けはありますか?
編集
これは私のフラグメントレイアウトです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/fragment_grid_view"
android:layout_width="match_parent"
android:layout_height="150dp"
android:numColumns="auto_fit" >
</GridView>
<Button
android:id="@+id/fragment_grid_view_add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Add Picture" />
</LinearLayout>
EDIT2
私のボタンと重なっている別のボタンがあったことが判明したため、そのボタンは私のボタンではなく onClick イベントを受け取っていました。EclipseでHierarchyビューを使用したときに、それを理解できました。非常に便利です。