android - expandablelistview 在我的应用程序中第二次运行时显示黑屏
问题描述
我正在制作一个具有可扩展列表视图的应用程序,我强制 youtube 视频全屏启动。我尝试了其他解决方案,但没有奏效。因此,当我单击可扩展列表视图的项目时,我将其链接到强制全屏支持片段,第一个项目运行良好,但是当我单击后退按钮并单击另一个项目时,YouTube 视频崩溃并且屏幕变黑。所以基本上,如果我关闭 YouTube 应用程序或者我不强制全屏显示项目运行良好,所以我尝试了所有这些代码,但没有成功。提示:不是 YouTube API。我也尝试了所有这些代码
这是我的可扩展适配器活动:
@Override
public View getChildView (int i, int i1, boolean b, View view, ViewGroup viewGroup) {
String listChild = (String) getChild(i, i1);
// initialize view
if (view == null) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.listitem, null);
}
// initialize and assign variables
TextView child = view.findViewById(R.id.child);
//set text on textview
child.setText(listChild);
//set on click listener
child.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View view) {
if (i == 0 && i1 == 0) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=kISB5sum51Y"));
intent.putExtra("force_fullscreen", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
if (i == 0 && i1 == 1) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=dLDj2TTyMGM"));
intent.putExtra("force_fullscreen", true);
context.startActivity(intent);
}
if (i == 1 && i1 == 0) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=ZuAzy1raPmE"));
intent.putExtra("force_fullscreen", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
if (i == 1 && i1 == 1) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=9bSsxmCguW8"));
intent.putExtra("force_fullscreen", true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
});
return view;
}
这是清单:
这是 expandaplistview :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
/>
</RelativeLayout>
这是组列表:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
>
<TextView
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:padding="20dp"
android:textSize="20sp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 listItem :
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="55dp">
<TextView
android:id="@+id/child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingBottom="5dp"
android:textSize="23sp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
推荐阅读
- vue.js - VueJS:仅在首次加载后启用转换
- asp.net - PowerBI Desktop 返回 404 获取 OData API 但在 Fiddler 中工作正常
- c++ - 提高对 char 数组中指针语法的理解
- php - Imagick 无法读取文件(pdf)但能够读取图像
- java - HTTP POST 请求引发 FileNotFound 异常(但在 Postman 中有效)
- hex - 将十六进制转换为文本问题
- node.js - 如何将对象添加到另一个数组内的数组中?
- ios - 表格视图单元格说明
- virtual-memory - 寻找需求分页的下限
- haskell - Haskell中函数参数是如何传递的?