Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. //getting the list view
  2. ListView userListView = (ListView) findViewById(R.id.users_ListView);
  3.  
  4. //creating an array to represnt what ever you want
  5. ArrayList<String> users = new ArrayList<>();
  6. for (int i = 0; i < 10 ; i++) {
  7. //populate the array
  8. String s = "user " + i;
  9. users.add(s);
  10. }
  11. //setting up adapter to the array
  12. ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, users);
  13. //connecting the list view to get the data to show from the adapter
  14. userListView.setAdapter(adapter);
  15.  
  16. //changing the arrayList by adding or subtracting
  17. String s = "another user";
  18. users.add(s);
  19.  
  20. //update the adapter and list view with this command
  21. adapter.notifyDataSetChanged();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement