Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //getting the list view
- ListView userListView = (ListView) findViewById(R.id.users_ListView);
- //creating an array to represnt what ever you want
- ArrayList<String> users = new ArrayList<>();
- for (int i = 0; i < 10 ; i++) {
- //populate the array
- String s = "user " + i;
- users.add(s);
- }
- //setting up adapter to the array
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, users);
- //connecting the list view to get the data to show from the adapter
- userListView.setAdapter(adapter);
- //changing the arrayList by adding or subtracting
- String s = "another user";
- users.add(s);
- //update the adapter and list view with this command
- adapter.notifyDataSetChanged();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement