Java 如何通过单击片段内的Linearlayout从片段Cals启动新活动?下面是我的代码,但这不起作用

Java 如何通过单击片段内的Linearlayout从片段Cals启动新活动?下面是我的代码,但这不起作用,java,android,xml,android-layout,android-fragments,Java,Android,Xml,Android Layout,Android Fragments,当我在片段中单击linearlayout时,它不会给出任何错误,但不会启动新活动。我的代码有错误吗?请有人帮帮我。 这个片段是我的项目的xml文件代码 Fragment_one.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_

当我在片段中单击linearlayout时,它不会给出任何错误,但不会启动新活动。我的代码有错误吗?请有人帮帮我。 这个片段是我的项目的xml文件代码

Fragment_one.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"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1"
        >
        <LinearLayout
            android:id="@+id/Lbid"
            android:layout_width="wrap_content"
            android:layout_marginTop="30dp"
            android:layout_height="wrap_content">
            <ProgressBar

                style="?android:attr/progressBarStyleHorizontal"
                android:id="@+id/pbb"
                android:layout_marginLeft="15dp"
                android:layout_width="180dp"
                android:layout_height="25dp"
                android:progress="50"
                android:progressDrawable="@drawable/bidonpb"

                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Bid on"
                android:id="@+id/tv"
                android:layout_marginLeft="2dp"
                />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/Lap"
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"

            android:layout_height="wrap_content">
            <ProgressBar

                style="?android:attr/progressBarStyleHorizontal"
                android:id="@+id/pbap"
                android:layout_marginLeft="15dp"
                android:layout_width="180dp"
                android:layout_height="25dp"
                android:progress="60"
                android:progressDrawable="@drawable/appb"

                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Awaiting Payments"
                android:layout_marginLeft="2dp"
                />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/LO"
            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"

            android:layout_height="wrap_content">
            <ProgressBar

                style="?android:attr/progressBarStyleHorizontal"
                android:id="@+id/pbo"
                android:layout_marginLeft="15dp"
                android:layout_width="180dp"
                android:layout_height="25dp"
                android:progress="20"
                android:progressDrawable="@drawable/opb"

                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Overdue"
                android:layout_marginLeft="2dp"
                />
        </LinearLayout>
        <LinearLayout

            android:layout_width="wrap_content"
            android:layout_marginTop="20dp"
            android:id="@+id/LA"
            android:layout_height="wrap_content">
            <ProgressBar

                style="?android:attr/progressBarStyleHorizontal"
                android:id="@+id/pba"
                android:layout_marginLeft="15dp"
                android:layout_width="180dp"
                android:layout_height="25dp"

                android:progress="45"
                android:progressDrawable="@drawable/assignedpb"

                />
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Assigned"
                android:layout_marginLeft="2dp"
                />

        </LinearLayout>

    </LinearLayout>
</LinearLayout>

onCreateView()方法中存在问题。你回来

  return inflater.inflate(
            R.layout.fragment_one, container, false);
这将生成一个新视图,而不包含您添加的侦听器。你应该这样做

return view;

因为视图是包含您添加的侦听器的布局的视图。

您应该使用Intent.FLAG\u ACTIVITY\u NEW\u TASK和您的Intent

//像这样
intent.setFlags(intent.FLAG\u活动\u新任务)

谢谢你救了我一天。我已经浪费了一个。