Advertisement
obernardovieira

[Android] notifySetDataChanged example

May 20th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. //not by me, but tested
  2.  
  3. private ArrayList<String> titles;
  4. private MyListAdapter adapter;
  5. private ListView myListView;
  6.  
  7. @Override
  8. public void onCreate(Bundle savedInstanceState){
  9.     super.onCreate(savedInstanceState);
  10.     setContentView(R.layout.main_activity);
  11.  
  12.     myListView = (ListView) findViewById(R.id.my_list);
  13.  
  14.     titles = new ArrayList<String>()
  15.  
  16.     for(int i =0; i<20;i++){
  17.         titles.add("Title "+i);
  18.     }
  19.  
  20.     adapter = new MyListAdapter(this, titles);
  21.     myListView.setAdapter(adapter);
  22. }
  23.  
  24.  
  25. @Override
  26. public void onResume(){
  27.     super.onResume();
  28.     // first clear the items and populate the new items
  29.     titles.clear();
  30.     for(int i =0; i<20;i++){
  31.         titles.add("New Title "+i);
  32.     }
  33.     adapter.notifySetDataChanged();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement