All my listviews in my application are using the empty property to show a progressdialog while loading some web content:
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@android:id/empty" android:gravity="center">
<ProgressBar android:id="@+id/progressBar1" android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar>
</RelativeLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
This is great and work fine the first time, but unfortunately, if I want to reload the listview, I expect the progressdialog to show again!
but, I can use:
getListView().setAdapter(null);
or
getListView().setAdapter(new TweetItemAdapter(getActivity(),R.layout.row_tweet,new ArrayList<Tweet>()));
I xon’t get any dialog, just an empty view.
So basically my question is “how to show the empty layout again during the second loading of the listview?
EDIT: With comment below, I tried :
@Override
public void onResume() {
super.onResume();
TweetItemAdapter test = (TweetItemAdapter) getListView().getAdapter();
if(test != null){
test.clear();
test.notifyDataSetChanged();
}
loadTweets(this, getListView());
}
Still doesn’t show the progressdialog, I get an empty view while loading. (EXCEPT for first loading that works perfectly)
Approach: Add in you XML the view that you want to show up when the
ListViewis empty. Then when populating theListViewcheck for the length of the data supplier you use in you adapter inside thegetView()method (if it is null or its length is 0) if it isnull/0-lengththen instantiate that view and change its visibility toView.VISIBLE. Or usegetListView().setEmptyView(findViewById(R.id.myemptyview));Remark: I think there is no need to clear you adapter
test.clear()since (I assume somewhere inloadTweets()you have adapter and callnotifyDataSetChanged()again) the listview will repopulate with the new data.Question: Do you reinstantiate the progress dialog whenever you call
notifyDataSetChanged()because my logic says that: progress dialog must be shown whenever you do fetching, i.e repopulating the listview with data? (I might be wrong)