notifyDataSetChanged() on my adapter does not update the listview, why?

前端 未结 3 1621
迷失自我
迷失自我 2021-01-24 03:53

I have a activity that extends listactivity, extended in this class i have a class that extends baseadapter.

now in my listactivity i have this onCreate

         


        
3条回答
  •  忘掉有多难
    2021-01-24 04:58

    If the adapter is already set, setting it again will not refresh the listview. Instead first check if the listview has a adapter and then call the appropriate method.

    I think its not a very good idea to create a new instance of the adapter while setting the list view. Instead, create an object.

    BuildingAdapter adapter = new BuildingAdapter(context);
    
        if(getListView().getAdapter() == null){ //Adapter not set yet.
         setListAdapter(adapter);
        }
        else{ //Already has an adapter
        adapter.notifyDataSetChanged();
        }
    

提交回复
热议问题