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

て烟熏妆下的殇ゞ 提交于 2021-02-11 17:42:01

问题


I have one problem to use ListView. I search on the stackOverflow and other sites, but not fix again.

Genel.java:

public class Genel extends AppCompatActivity {
MediaController mediaController;
VideoView videoview;
ListView listView;
ArrayList<String> videoList;
ArrayAdapter adapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_genel);

    final VideoView videoview = findViewById(R.id.Videogenel);
    listView = (ListView) findViewById(R.id.lgvideo);
    videoList= new ArrayList<>();
    videoList.add("Genel Bilgiler");


    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.activity_list_item,videoList);
    listView.setAdapter(adapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch (position){
                case 0:
                    videoview.setVideoPath("/storage/A6D3-E544/videos/genel1.mp4");
                    break;
            }
            final MediaController mediacontroller = new MediaController(Genel.this);
            mediacontroller.setAnchorView(videoview);

            videoview.setMediaController(mediacontroller);
            videoview.requestFocus();
            videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                        @Override
                        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                            videoview.setMediaController(mediacontroller);
                            mediacontroller.setAnchorView(videoview);
                        }
                    });
                }
            });

            videoview.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                @Override
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    Log.d("API123", "What " + what + " extra " + extra);
                    return false;
                }
            });

            videoview.setMediaController(mediaController);
            videoview.start();


        }
    });

XML file:

 <VideoView
    android:id="@+id/Videogenel"
    android:layout_width="wrap_content"
    android:layout_height="300dp"
    android:layout_gravity="center"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="76dp" />

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lgvideo"
    android:layout_below="@+id/Videogenel"
    android:layout_centerHorizontal="true">

</ListView>

activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

  </RelativeLayout>

When I use the android.R.layout.simple_list_item_1 everything works fine, with the own xml file I get "java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView". I need suggestions pls.


回答1:


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.



来源:https://stackoverflow.com/questions/60735350/arrayadapter-requires-the-resource-id-to-be-a-textview-error-for-androidx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!