Can not get gridView on item click listener

AndroidDev picture AndroidDev · Apr 12, 2012 · Viewed 17.6k times · Source

I can not get setOnItemClickListener of gridView in Fragment. What can be the problem?

Here is my code::

 public class MainMenuFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.main_menu_fragment, container, false);

        itemsGridViewObj = (GridView) view.findViewById(R.id.itemsGridView);



        itemsGridViewObj.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {

                Log.d(TAG, "--> onItemClick listener...");      // Can not getting this method.
                /*if(position == 1) {
                    FruitMenuFragment fruitMenuFragment = new FruitMenuFragment();
                    fragmentTransaction.replace(android.R.id.content, fruitMenuFragment);
                    fragmentTransaction.commit();
                }*/
            }
        });

        return view;
    }
}`

Answer

esse picture esse · Apr 25, 2012

You may need to set the following in your ButtonView. android:focusable="false" android:focusableInTouchMode="false"

see adding CheckBox to list row loses my onItemClick events?