Skip to content Skip to sidebar Skip to footer

Android Listview Trouble

I'm having problems trying to run an Android activity which implements a ListView, fills it with 20 elements and displays it: the activity crashes upon launch. Here are the relevan

Solution 1:

ArrayAdapter requires the resource ID to be a TextView

This just means, that you have to supply a layout with a TextView as an argument. The Adapter will bind this TextView to your data. But you are currently passing in your layout with your ListView in it.

So change this:

ArrayAdapter<String> adapter = newArrayAdapter<String>(this, R.layout.activity_third, android.R.id.list, values);

to this:

ArrayAdapter<String> adapter = newArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);

Post a Comment for "Android Listview Trouble"