Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android OnClick不';I don’我不在相对的地方工作_Android - Fatal编程技术网

Android OnClick不';I don’我不在相对的地方工作

Android OnClick不';I don’我不在相对的地方工作,android,Android,在我的应用程序relatevelayout setOnClickListener中,我无法找出这里的问题所在。 这是我的main.xml <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:lay

在我的应用程序relatevelayout setOnClickListener中,我无法找出这里的问题所在。 这是我的main.xml

<LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/profile_relative"
            android:layout_marginTop="1dp"
            android:id="@+id/profile_linear">

        <RelativeLayout
                android:id="@+id/profile_postButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="1dp">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_post_btn"
                    android:layout_centerInParent="true"
                    android:background="@drawable/post_selector_t"/>

            <TextView
                    android:id="@+id/profile_post_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:layout_centerInParent="true"
                    android:text="189"
                    android:textSize="14sp"/>
        </RelativeLayout>

        <RelativeLayout
                android:id="@+id/profile_gradeButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="1dp">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_likes_btn"
                    android:layout_centerInParent="true"
                    android:background="@drawable/likes_selector_t"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_likes_text"
                    android:layout_marginTop="20dp"
                    android:layout_centerInParent="true"
                    android:text="597"
                    android:textSize="14sp"/>
        </RelativeLayout>

        <RelativeLayout
                android:id="@+id/profile_subscriptionButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="1dp">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_signed_on_btn"
                    android:layout_centerInParent="true"
                    android:background="@drawable/signed_on_selector_t"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_signed_on_text"
                    android:layout_marginTop="20dp"
                    android:layout_centerInParent="true"
                    android:text="85"
                    android:textSize="14sp"/>
        </RelativeLayout>

        <RelativeLayout
                android:id="@+id/profile_subsribersButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="1dp">

            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_followers_btn"
                    android:layout_centerInParent="true"
                    android:background="@drawable/followers_selector_t"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/profile_followers_text"
                    android:layout_marginTop="20dp"
                    android:layout_centerInParent="true"
                    android:text="118"
                    android:textSize="14sp"/>
        </RelativeLayout>
    </LinearLayout>
你知道我错过了什么吗

在XML中添加:

android:onClick="onClick";

到每个按钮。

我认为您必须将
onClick
块代码移到
onCreate

   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.profile, container, false);

        view.findViewById(R.id.profile_postButton).setOnClickListener(this);
        view.findViewById(R.id.profile_gradeButton).setOnClickListener(this);
        view.findViewById(R.id.profile_subsribersButton).setOnClickListener(this);
        view.findViewById(R.id.profile_subscriptionButton).setOnClickListener(this);
} 


@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.profile_postButton:
            System.out.println("AA");

            break;
        case R.id.profile_gradeButton:
            System.out.println("GG");

            break;
        case R.id.profile_subscriptionButton:
            System.out.println("EE");

            break;
        case R.id.profile_subsribersButton:
            System.out.println("DD");

            break;
    }

似乎onClick是在onCreateView中实现的。你能纠正一下吗?我想不是这样的
   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.profile, container, false);

        view.findViewById(R.id.profile_postButton).setOnClickListener(this);
        view.findViewById(R.id.profile_gradeButton).setOnClickListener(this);
        view.findViewById(R.id.profile_subsribersButton).setOnClickListener(this);
        view.findViewById(R.id.profile_subscriptionButton).setOnClickListener(this);
} 


@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.profile_postButton:
            System.out.println("AA");

            break;
        case R.id.profile_gradeButton:
            System.out.println("GG");

            break;
        case R.id.profile_subscriptionButton:
            System.out.println("EE");

            break;
        case R.id.profile_subsribersButton:
            System.out.println("DD");

            break;
    }