Skip to content Skip to sidebar Skip to footer

Updating A Listfragment Based On Async Task Result

Scenario : I am having a list fragment which displays a list of friends. When an list item is pressed, I'm showing the details of the friend in a dialog fragment. Problem: In the d

Solution 1:

So you will be populating the ListView with an ArrayList.

  • Delete the Item from the ArrayList with index = ListViewItemIndex clicked.
  • call notifyDataSetChanged on the Adapter you are using.

Solution 2:

No problem. I'm guessing the ListFragment is reading from some data source - be it an ArrayAdapter or a SimpleCursorAdapter (or something similar) - and your task is also modifying that source. When the AsyncTask finishes, you should just be able to get that fragment and update the underlying data. For example:

// ...voidonPostExecute(Void result) {
    ListFragmentlFrag= (ListFragment) getFragmentManager().findFragmentById(R.id.yourListFragment);
    BaseAdapteradapter= (BaseAdapter) lFrag.getListAdapter();
    adapter.notifyDataSetChanged();
}

Post a Comment for "Updating A Listfragment Based On Async Task Result"