Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. mButton.setOnClickListener(new View.OnClickListener() {
  2. public void onClick(View v) {
  3. refreshListView(data);
  4. }
  5. });
  6.  
  7. public void refreshListView(ArrayList data) {
  8. // I am setting setNotifyOnChange() to false
  9. // to prevent notifyDataSetChanged() to be triggered twice, by clear() and by addAll()
  10. mArrayAdapter.setNotifyOnChange(false)
  11. mArrayAdapter.clear();
  12. mArrayAdapter.addAll(data);
  13. // I am triggering notifyDataSetChanged() explicitely
  14. mArrayAdapter.notifyDataSetChanged();
  15. mListView.post(new Runnable() {
  16. @Override
  17. public void run() {
  18. // this is to reset to the top of the list, after the list has been populated
  19. mListView.setSelectionAfterHeaderView();
  20. }
  21. });
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement