listview OnItemClick listener not work in fragment

后端 未结 4 874
予麋鹿
予麋鹿 2020-12-18 07:51

I used listview in fragment but I used list onItemClick listener not working. My code below and how to perfect solution.

 public class StoreProf         


        
4条回答
  •  既然无缘
    2020-12-18 08:48

    Here you go: Use onActivityCreated() instead and use the code here:

    @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onActivityCreated(savedInstanceState);
    
            ListView lv1 = (ListView)getActivity().findViewById(R.id.myStore_listview);
            adtstore = new MyListAdapter(getActivity().getApplicationContext());
            lv.setAdapter(adtstore);
            lv1.setOnItemClickListener(new OnItemClickListener() {
    
                @Override
                public void onItemClick(AdapterView arg0, View arg1, int position,
                        long arg3) {
    
                    Toast.makeText(getActivity(), "Item clicked : " + position, Toast.LENGTH_SHORT).show();
    
                }
    
            });
    
        }
    

    Should work now.. :)

提交回复
热议问题