-1

Don't know why the onItemClick event not working...

public class FragmentList extends Fragment {
    View rootView;
    ListView list;


    public FragmentList (){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_list, container, false);
        list=(ListView)rootView.findViewById(R.id.list);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                Log.i("test", String.valueOf(position));

                }
            });
        return rootView;
    }
}

Anyone has idea on this. thanks so much

user3691709
  • 131
  • 3
  • 8
  • 1
    you did not set your adapter for that listview therefore no cliking can be registered. – Rod_Algonquin Mar 31 '15 at 03:02
  • your Listview size = 0, width = 0, height = 0 because of no child. So where the place u can click in this? You need setadapter first – kemdo Mar 31 '15 at 03:09

1 Answers1

3

If any row item of list contains focusable or clickable view then OnItemClickListener won't work.

The row item must have a param like android:descendantFocusability="blocksDescendants".

Click here for more information.

Community
  • 1
  • 1
adsion
  • 187
  • 3
  • 13
  • I have a listview inside a fragment. When clicking an item, it will jump to a detail fragment by replacing. However, when I click the back button from the detail fragment, it jumps back to the listview fragment that requiring to load all the data again. Is it possible to keep all the listview item and status when back. Thanks. – user3691709 Mar 31 '15 at 03:59
  • @user3691709,you can judge if your rootView empty or not when call onCreateView method,and then decide if request to load all the data or not – adsion Mar 31 '15 at 05:52