"Arrayadapter Requires the Resource Id to Be a Textview" Xml Problems

ArrayAdapter requires the resource ID to be a TextView XML problems

The ArrayAdapter requires the resource ID to be a TextView XML exception means you don't supply what the ArrayAdapter expects. When you use this constructor:

new ArrayAdapter<String>(this, R.layout.a_layout_file, this.file)

R.Layout.a_layout_file must be the id of a xml layout file containing only a TextView(the TextView can't be wrapped by another layout, like a LinearLayout, RelativeLayout etc!), something like this:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
// other attributes of the TextView
/>

If you want your list row layout to be something a little different then a simple TextView widget use this constructor:

new ArrayAdapter<String>(this, R.layout.a_layout_file, 
R.id.the_id_of_a_textview_from_the_layout, this.file)

where you supply the id of a layout that can contain various views, but also must contain a TextView with and id(the third parameter) that you pass to your ArrayAdapter so it can know where to put the Strings in the row layout.

“ArrayAdapter requires the resource ID to be a TextView” issue

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);

ArrayAdapter requires the resource ID to be a TextView error for AndroidX

use: ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,videoList);

instead of the: ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.activity_list_item,videoList);

remove android in android.R.layout.activity_list_item, and use the support_simple_spinner_dropdown_item instead of the activity_list_item.

ArrayAdapter requires the resource ID to be a TextView sometimes in time execution

I suppose you need to use the following ArrayAdapter constructor mentioned here:

ArrayAdapter (Context context, 
int resource,
int textViewResourceId,
T[] objects)

In your case:

ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getActivity(), R.layout.spinner_text, R.id.text1, numbers);

Error: ArrayAdapter requires the resource ID to be a TextView

As we can read in http://developer.android.com/reference/android/widget/ArrayAdapter.html
ArrayAdapter just works with strings on textviews. You can use this constructor

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

specifyng the id of a TextView inside your layout or override

getView(int, View, ViewGroup) 

returning a view of your custom type.

ArrayAdapter requires the resource ID to be a TextView, ListView cannot be cast to TextView

I think the problem is here:

new ArrayAdapter<String>(getActivity(), R.layout.platformsfragment, android.R.id.list, MainActivity.titles)

Try to replace this code with:

new ArrayAdapter<String>(getActivity(), R.layout.listitem, android.R.id.text1, MainActivity.titles)

listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView></LinearLayout>

ArrayAdapter requires the resource ID to be a TextView

chat2.xml must contain a TextView, not a LinearLayout. Right now you have your TextView wrapped in a LinearLayout, therefore you are getting the Exception.

The constructor or ArrayAdapter you are using in ChatArrayAdapter by calling super(...) expects the R.id. for a TextView, not LinearLayout.

See here



Related Topics



Leave a reply



Submit