java arraylist if you don 27t want to use add 28 29

Solutions on MaxInterview for java arraylist if you don 27t want to use add 28 29 by the best coders in the world

showing results for - "java arraylist if you don 27t want to use add 28 29"
Erica
19 Sep 2017
1public class MainActivity extends AppCompatActivity {
2
3    @Override
4    protected void onCreate(Bundle savedInstanceState) {
5        super.onCreate(savedInstanceState);
6        setContentView(R.layout.activity_main);
7
8
9        ListView myListView = (ListView) findViewById(R.id.myListView);
10
11        final ArrayList<String> myFriendsList = new ArrayList<String>(asList("Friend1", "Friend2", "Friend3", "Friend4", "Friend5"));
12
13        // set the layout of the list
14        ArrayAdapter<String> friendsArrayAdapter = new ArrayAdapter<String>(this,
15                                                android.R.layout.simple_list_item_1, myFriendsList);
16
17        // connect adapter to myFriendsList
18        myListView.setAdapter(friendsArrayAdapter);
19
20        // set onClickListener
21        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
22            @Override
23            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
24
25                Toast.makeText(MainActivity.this, myFriendsList.get(position), Toast.LENGTH_SHORT).show();
26            }
27        });
28
29
30
31
32    }
33}