ListFragment OnListItemClick not being called

后端 未结 11 1471
盖世英雄少女心
盖世英雄少女心 2020-11-27 05:53

I have a class that extends ListFragment, and it overrides the OnListItemClick method. I am also doing this in another ListFragment the same way (and the method gets called)

11条回答
  •  甜味超标
    2020-11-27 06:18

    Only workaround so far, use a Fragment and a ListView then use setOnItemClickListener() which would make the ListFragment, and all its' convenience obsolete... After I created a new class containing exactly the same code (only the class name changed) and built the project on a different machine it "magically" worked (Still same API-Level). Below the code that worked. I also tried project->clean which usually fixes most problems, but that did not work eiter.

    public class ContainerFragment extends ListFragment {
    
        private ContainerFragmentListener listener;
    
        public ContainerFragment(ContainerFragmentListener listener) {
            super();
            this.listener = listener;
        }
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            setListAdapter(new ContainerAdapter(getActivity()));
        }
    
         @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
            Container container = (Container) getListAdapter().getItem(position);
            listener.containerSelected(container.id);
        }
    
    
    }
    

提交回复
热议问题