How to refresh ListView on login in android

My application has three tabs with a display ListView

inside each one. How do I write code to refresh ListView

when clicked between tabs?

@Override
public void onTabChanged(String tabId) {        
    if(tabId == "tab_1")
    {
        refresh ListView ???
    }   

}

      

+2


source to share


3 answers


You are not updating ListView

. Make sure the baseline Adapter

contains the latest data and it will work with ListView

to display it. So, for example, if you are using SimpleCursorAdapter

, call requery()

on Cursor

.



+3


source


If you want to update manually, you can call notifyDataSetChanged()

on Adapter

.



+4


source


You actually have to do two things: - you have to ask the adapter to notify the ListView of new data changes: notifyDataSetChanged () but this will take effect the next time the ListView needs to show the view (say after the scroll list). Another problem is that the ListView won't ask for the number of rows in the list, so if the list gets shorter, you'll get a null pointer exception :)

I prefer to use something like:

if(filterProvider.containsChildren(position)){
// go into the hierarchy
    filterProvider.navigateToChildren(position);
    adapter.notifyDataSetChanged();
    adapter.notifyDataSetInvalidated();
    listView.invalidateViews();
}else{
    int ID = (int)filterProvider.getIdFromPosition(position);
    activity.setResult(ID);
    activity.finish();
}

      

The code is part of a multilevel list (with hierarchy)

Hello Sasha Rudan

0


source







All Articles