Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- refreshListView(data);
- }
- });
- public void refreshListView(ArrayList data) {
- // I am setting setNotifyOnChange() to false
- // to prevent notifyDataSetChanged() to be triggered twice, by clear() and by addAll()
- mArrayAdapter.setNotifyOnChange(false)
- mArrayAdapter.clear();
- mArrayAdapter.addAll(data);
- // I am triggering notifyDataSetChanged() explicitely
- mArrayAdapter.notifyDataSetChanged();
- mListView.post(new Runnable() {
- @Override
- public void run() {
- // this is to reset to the top of the list, after the list has been populated
- mListView.setSelectionAfterHeaderView();
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement