按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

时间:2022-12-01 20:33:20
RT,按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

13 个解决方案

#1


麻烦贴点代码,这样问谁能知道啊

#2


==。可能第一次去执行其他的了吧,还是看下代码。

#3


引用 1 楼 u014165119 的回复:
麻烦贴点代码,这样问谁能知道啊
<?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="wrap_content"
    android:background="@color/dark_white"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="@drawable/bg_white_radius"
        android:orientation="vertical">

        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/iv_userimg"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/bg_grey_radius"
            android:layout_margin="@dimen/margin_horizontal_10_dip" />

        <TextView
            android:id="@+id/tv_username"
            android:layout_alignTop="@id/iv_userimg"
            android:layout_toRightOf="@id/iv_userimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="aaa"
            android:textColor="@color/black"
            android:textSize="@dimen/word_size_09" />

        <TextView
            android:id="@+id/it_from"
            android:layout_toRightOf="@id/iv_userimg"
            android:layout_alignBottom="@+id/iv_userimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ssdds"
            android:textSize="@dimen/word_size_05" />
    </RelativeLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/bg_grey_radius"
            android:orientation="vertical">

            <TextView
                android:id="@+id/topic_title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:layout_marginTop="5dip"
                android:text="aaa"
                android:textColor="@color/black"
                android:textSize="@dimen/word_size_07" />

            <TextView
                android:id="@+id/topic_content"
                android:layout_width="fill_parent"
                android:text="vvv"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:textSize="@dimen/word_size_05" />
        </LinearLayout>
        <GridView
            android:id="@+id/gv_piclist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:numColumns="auto_fit"
            android:horizontalSpacing="10dp"
            android:verticalSpacing="10dp"
            android:columnWidth="90dp"
            android:stretchMode="columnWidth"
            android:gravity="center"/>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dip"
            android:layout_marginBottom="10dip"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="@string/topic_time" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dip"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <ImageView
                            android:id="@+id/item_topic_comment"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/heart_pink" />

                        <TextView
                            android:id="@+id/item_topic_heart"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:text="@string/topic_like_num"
                            android:textColor="@color/white_grey" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/comment" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>
            </LinearLayout>


        </LinearLayout>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dip"
        android:layout_marginLeft="20dip"
        android:text="@string/topic_toupiao"
        android:textColor="@color/black"
        android:textSize="@dimen/word_size_09" />

    <ListView
        android:id="@+id/head_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:choiceMode="singleChoice"
        android:divider="@null" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:background="@color/white"
        android:orientation="vertical">

        <Button
            android:id="@+id/bt_vote"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:background="@drawable/btn_bg_pink"
            android:text="提交查看投票结果" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:background="@drawable/banner_init" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dip"
        android:text="@string/questions_star_reply"
        android:textSize="@dimen/word_size_09" />
</LinearLayout>

bt_vote这个Button,第一次点没反应,大概是没获取到焦点,请问怎么解决

#4


帮忙顶顶 按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#5


改成onClick来试试。

#6


在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#7


正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。

#8


我估计是其他控件持有了焦点

#9


引用 7 楼 crazy1235 的回复:
正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。
    View.OnClickListener voteClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bt_vote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String choice = "";
                    selected.clear();
                    int k = voteData.size();
                    for (int i = 0; i < k; i++) {
                        if (voteData.get(i).getChecked()) {
                            selected.add(i);
                            choice = voteData.get(i).getName();
                        }
                    }
                    k = selected.size();
                    if (k == 0) {
                        Toast.makeText(activity, "请选择投票项", Toast.LENGTH_SHORT).show();
                    } else {
                        bt_vote.setVisibility(View.GONE);
                        adapter = new MyListAdapter(voteData);
                        head_listview.setAdapter(adapter);
                    }
                }
            });
        }
    };

#10


引用 9 楼 u014765620 的回复:
Quote: 引用 7 楼 crazy1235 的回复:

正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。
    View.OnClickListener voteClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bt_vote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String choice = "";
                    selected.clear();
                    int k = voteData.size();
                    for (int i = 0; i < k; i++) {
                        if (voteData.get(i).getChecked()) {
                            selected.add(i);
                            choice = voteData.get(i).getName();
                        }
                    }
                    k = selected.size();
                    if (k == 0) {
                        Toast.makeText(activity, "请选择投票项", Toast.LENGTH_SHORT).show();
                    } else {
                        bt_vote.setVisibility(View.GONE);
                        adapter = new MyListAdapter(voteData);
                        head_listview.setAdapter(adapter);
                    }
                }
            });
        }
    };



点击事件是对的。你有给button设置吗?
设置了之后,建议吧你的事件中的代码换成简单的吐司,看看有没有。如果有的话,就是你点击事件的逻辑的问题了、。

#11


引用 6 楼 gao_chun 的回复:
在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?


这个是父控件在子控件之前拿到焦点,应该用afterDescendants

#12


引用 11 楼 lingang1359 的回复:
Quote: 引用 6 楼 gao_chun 的回复:

在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?


这个是父控件在子控件之前拿到焦点,应该用afterDescendants

恩,临时截了个图,箭头指错地方了,我只是想告诉他有这么三个属性可以试试    按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#13


你好我也刚刚遇到这种问题,在网上问了找了很久也没找到解决方法,请问你解决了吗

#1


麻烦贴点代码,这样问谁能知道啊

#2


==。可能第一次去执行其他的了吧,还是看下代码。

#3


引用 1 楼 u014165119 的回复:
麻烦贴点代码,这样问谁能知道啊
<?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="wrap_content"
    android:background="@color/dark_white"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="@drawable/bg_white_radius"
        android:orientation="vertical">

        <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/iv_userimg"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/bg_grey_radius"
            android:layout_margin="@dimen/margin_horizontal_10_dip" />

        <TextView
            android:id="@+id/tv_username"
            android:layout_alignTop="@id/iv_userimg"
            android:layout_toRightOf="@id/iv_userimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="aaa"
            android:textColor="@color/black"
            android:textSize="@dimen/word_size_09" />

        <TextView
            android:id="@+id/it_from"
            android:layout_toRightOf="@id/iv_userimg"
            android:layout_alignBottom="@+id/iv_userimg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ssdds"
            android:textSize="@dimen/word_size_05" />
    </RelativeLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@drawable/bg_grey_radius"
            android:orientation="vertical">

            <TextView
                android:id="@+id/topic_title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:layout_marginTop="5dip"
                android:text="aaa"
                android:textColor="@color/black"
                android:textSize="@dimen/word_size_07" />

            <TextView
                android:id="@+id/topic_content"
                android:layout_width="fill_parent"
                android:text="vvv"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:textSize="@dimen/word_size_05" />
        </LinearLayout>
        <GridView
            android:id="@+id/gv_piclist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:numColumns="auto_fit"
            android:horizontalSpacing="10dp"
            android:verticalSpacing="10dp"
            android:columnWidth="90dp"
            android:stretchMode="columnWidth"
            android:gravity="center"/>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dip"
            android:layout_marginBottom="10dip"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="@string/topic_time" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dip"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <ImageView
                            android:id="@+id/item_topic_comment"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:src="@drawable/heart_pink" />

                        <TextView
                            android:id="@+id/item_topic_heart"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:singleLine="true"
                            android:text="@string/topic_like_num"
                            android:textColor="@color/white_grey" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/comment" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toLeftOf="@id/item_topic_heart"
                        android:src="@drawable/heart_pink" />
                </LinearLayout>
            </LinearLayout>


        </LinearLayout>

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dip"
        android:layout_marginLeft="20dip"
        android:text="@string/topic_toupiao"
        android:textColor="@color/black"
        android:textSize="@dimen/word_size_09" />

    <ListView
        android:id="@+id/head_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:choiceMode="singleChoice"
        android:divider="@null" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:background="@color/white"
        android:orientation="vertical">

        <Button
            android:id="@+id/bt_vote"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dip"
            android:layout_marginRight="20dip"
            android:background="@drawable/btn_bg_pink"
            android:text="提交查看投票结果" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:background="@drawable/banner_init" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dip"
        android:text="@string/questions_star_reply"
        android:textSize="@dimen/word_size_09" />
</LinearLayout>

bt_vote这个Button,第一次点没反应,大概是没获取到焦点,请问怎么解决

#4


帮忙顶顶 按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#5


改成onClick来试试。

#6


在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#7


正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。

#8


我估计是其他控件持有了焦点

#9


引用 7 楼 crazy1235 的回复:
正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。
    View.OnClickListener voteClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bt_vote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String choice = "";
                    selected.clear();
                    int k = voteData.size();
                    for (int i = 0; i < k; i++) {
                        if (voteData.get(i).getChecked()) {
                            selected.add(i);
                            choice = voteData.get(i).getName();
                        }
                    }
                    k = selected.size();
                    if (k == 0) {
                        Toast.makeText(activity, "请选择投票项", Toast.LENGTH_SHORT).show();
                    } else {
                        bt_vote.setVisibility(View.GONE);
                        adapter = new MyListAdapter(voteData);
                        head_listview.setAdapter(adapter);
                    }
                }
            });
        }
    };

#10


引用 9 楼 u014765620 的回复:
Quote: 引用 7 楼 crazy1235 的回复:

正常来说是不可能的。
看看你的点击事件怎么写的,代码贴出来。
    View.OnClickListener voteClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bt_vote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String choice = "";
                    selected.clear();
                    int k = voteData.size();
                    for (int i = 0; i < k; i++) {
                        if (voteData.get(i).getChecked()) {
                            selected.add(i);
                            choice = voteData.get(i).getName();
                        }
                    }
                    k = selected.size();
                    if (k == 0) {
                        Toast.makeText(activity, "请选择投票项", Toast.LENGTH_SHORT).show();
                    } else {
                        bt_vote.setVisibility(View.GONE);
                        adapter = new MyListAdapter(voteData);
                        head_listview.setAdapter(adapter);
                    }
                }
            });
        }
    };



点击事件是对的。你有给button设置吗?
设置了之后,建议吧你的事件中的代码换成简单的吐司,看看有没有。如果有的话,就是你点击事件的逻辑的问题了、。

#11


引用 6 楼 gao_chun 的回复:
在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?


这个是父控件在子控件之前拿到焦点,应该用afterDescendants

#12


引用 11 楼 lingang1359 的回复:
Quote: 引用 6 楼 gao_chun 的回复:

在父布局上加这个属性试试        android:descendantFocusability=""   

有三个属性:
按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?


这个是父控件在子控件之前拿到焦点,应该用afterDescendants

恩,临时截了个图,箭头指错地方了,我只是想告诉他有这么三个属性可以试试    按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?

#13


你好我也刚刚遇到这种问题,在网上问了找了很久也没找到解决方法,请问你解决了吗