Custom Adapter getView() method is not called

后端 未结 6 1310
悲&欢浪女
悲&欢浪女 2020-11-22 09:49

Here is the code of the fragment in which I am setting a custom adapter to the list.

There no errors but the ListView is empty. I have implemented

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 10:13

    I faced similar problem. Here is a simple work around to solve it:

    In your onCreateView, you will have to wait before the view gets created. So change your lines from this:

    mList = (ListView)v.findViewById(R.id.list);
    mList.setAdapter(adapter);
    

    CHANGE THE ABOVE TWO LINES INTO:

    mList = (ListView)v.findViewById(R.id.list);
    mList.post(new Runnable() {
        public void run() {
            mList.setAdapter(adapter);
        }
    });
    

    Hope this will help others who would run into similar problem

提交回复
热议问题