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

十三邵 2015-07-30 09:24:46
RT,按钮第一次点没反应,要点第二次才能执行OnClick怎么解决?
...全文
1993 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
东土也 2017-10-08
  • 打赏
  • 举报
回复
你好我也刚刚遇到这种问题,在网上问了找了很久也没找到解决方法,请问你解决了吗
十三邵 2015-07-31
  • 打赏
  • 举报
回复
引用 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);
                    }
                }
            });
        }
    };
gao_chun 2015-07-31
  • 打赏
  • 举报
回复
引用 11 楼 lingang1359 的回复:
[quote=引用 6 楼 gao_chun 的回复:] 在父布局上加这个属性试试 android:descendantFocusability="" 有三个属性:
这个是父控件在子控件之前拿到焦点,应该用afterDescendants[/quote] 恩,临时截了个图,箭头指错地方了,我只是想告诉他有这么三个属性可以试试
lingang1359 2015-07-31
  • 打赏
  • 举报
回复
引用 6 楼 gao_chun 的回复:
在父布局上加这个属性试试 android:descendantFocusability="" 有三个属性:
这个是父控件在子控件之前拿到焦点,应该用afterDescendants
月盡天明 2015-07-31
  • 打赏
  • 举报
回复
引用 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);
                    }
                }
            });
        }
    };
[/quote] 点击事件是对的。你有给button设置吗? 设置了之后,建议吧你的事件中的代码换成简单的吐司,看看有没有。如果有的话,就是你点击事件的逻辑的问题了、。
_deadline 2015-07-30
  • 打赏
  • 举报
回复
我估计是其他控件持有了焦点
月盡天明 2015-07-30
  • 打赏
  • 举报
回复
正常来说是不可能的。 看看你的点击事件怎么写的,代码贴出来。
gao_chun 2015-07-30
  • 打赏
  • 举报
回复
在父布局上加这个属性试试 android:descendantFocusability=""

有三个属性:
boatwater 应用层 2015-07-30
  • 打赏
  • 举报
回复
改成onClick来试试。
seaseeseen 2015-07-30
  • 打赏
  • 举报
回复
帮忙顶顶
十三邵 2015-07-30
  • 打赏
  • 举报
回复
引用 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,第一次点没反应,大概是没获取到焦点,请问怎么解决
boatwater 应用层 2015-07-30
  • 打赏
  • 举报
回复
==。可能第一次去执行其他的了吧,还是看下代码。
StoneHui_ 2015-07-30
  • 打赏
  • 举报
回复
麻烦贴点代码,这样问谁能知道啊

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧