onListItemClick is not working for listview?

前端 未结 9 2160
一整个雨季
一整个雨季 2020-11-30 11:29

Hi onListItemClick for listview is not working. Here i am fetching datas from SQLite using AsyncTask and displaying it in a list view. And i wants to do some actions when a

9条回答
  •  遥遥无期
    2020-11-30 12:25

    I struggled with this for a while - none of the provided solutions worked for me. In the end I found that having a call to getListView() in my onViewCreated() method did the trick, although I have no idea why. This is for a Fragment rather than an Activity; not sure if this makes any difference.

    public class NewsListFragment extends ListFragment {
        private ListView listView;
        ...
        @Override
        public void onViewCreated(View view, Bundle savedInstanceState) {
            newsListView = getListView();
        }
    
        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            // this now works as expected
        }
    }
    

提交回复
热议问题