Skip to content Skip to sidebar Skip to footer

“arrayadapter Requires The Resource Id To Be A Textview” Issue

I seem to have problems using custom styles for ListView. All online searches (stackOverflow and other sites) pty much say the same: - create an my_style.xml layout file. - use it

Solution 1:

As error java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView clearly says. You need to pass the textview on which you need to show the data. Also, when you are using your own layout then R.java should belong to your project not android.R.

Change

arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.list_content, items);

to

arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_content, R.id.textview, items);

Solution 2:

Issue is because of you are passing wrong type of argument.

After seeing your code I can say you want to use following version of ArrayAdapter.

publicArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)

So following will work for you according to the code snippet provided by you.

arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_content, R.id.textview, items);

for different versions of arrayAdapter you can refer to : http://developer.android.com/reference/android/widget/ArrayAdapter.html

Solution 3:

What you are doing is declaring xml in your package and trying to access it from android.R.layout package. So, change

arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.list_content, items);

to

arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_content, items);

It'll work

Post a Comment for "“arrayadapter Requires The Resource Id To Be A Textview” Issue"