“arrayadapter Requires The Resource Id To Be A Textview” Issue
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"