gpt4 book ai didi

java - AndroidX "ArrayAdapter requires the resource ID to be a TextView"错误

转载 作者:行者123 更新时间:2023-12-01 17:54:58 25 4
gpt4 key购买 nike

我在使用 ListView 时遇到一个问题。我在 stackOverflow 和其他网站上搜索,但没有再次修复。

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 文件:

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

当我使用 android.R.layout.simple_list_item_1 时,一切正常,使用自己的 xml 文件,我得到“java.lang.IllegalStateException:ArrayAdapter 要求资源 ID 为 TextView”。我需要建议。

最佳答案

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

而不是:ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.activity_list_item,videoList);

删除android.R.layout.activity_list_item中的android ,并使用support_simple_spinner_dropdown_item而不是 activity_list_item .

关于java - AndroidX "ArrayAdapter requires the resource ID to be a TextView"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60735350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com