开发者

How to "reset" a listview and show again the @android:id/empty when repopulating

开发者 https://www.devze.com 2023-03-30 09:05 出处:网络
All my listviews in my application are using the empty property to show a progressdialog while loading some web content:

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 whil开发者_如何学编程e loading. (EXCEPT for first loading that works perfectly)


Approach: Add in you XML the view that you want to show up when the ListView is empty. Then when populating the ListView check for the length of the data supplier you use in you adapter inside the getView() method (if it is null or its length is 0) if it is null/0-length then instantiate that view and change its visibility to View.VISIBLE. Or use getListView().setEmptyView(findViewById(R.id.myemptyview));

Remark: I think there is no need to clear you adapter test.clear() since (I assume somewhere in loadTweets() you have adapter and call notifyDataSetChanged() 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消