In your onCreate()
, initialize the member variable adapter
instead of a local variable. Change this
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
to
adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);