首页 > 解决方案 > 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>

这是应用程序:https ://i.stack.imgur.com/UFgc3.jpg

标签: androidandroid-studioandroid-fragmentsexpandablelistview

解决方案


推荐阅读