Custom Adapter getView() method is not called

Solution 1:

The only reasons getView is not called are:

  1. getCount returns 0.
  2. you forget to call setAdapter on the ListView.
  3. If the ListView's visibility (or its container's visibility) is GONE. Thanks to @TaynãBonaldo for the valuable input.
  4. ListView is not attached to any viewport layout. That is, mListView = new ListView(...) is used without myLayout.addView(mListView).

In the onPostExcute, after you create a new instance of CarListAdapter I will suggest you to update the new instance to your ListView. Indeed you need to call again

 mList.setAdapter(adapter);

Edit: setAdapter should be always called on the ui thread, to avoid unexpected behaviours

Edit2:

The same applies to RecyclerView. Make sure that

  • getItemCount is returning a value grater than 0 (usually the dataset size)
  • both setLayoutManager and setAdapter have to be called on the UI Thread
  • The visibility of the widget has to be set to VISIBLE

Solution 2:

you must verify that the list has elements might have an error when adding items to your list . To verify , use the method:

adapter.getCount();

Solution 3:

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