事件分发,导致文字设置颜色(无效)记录

本文探讨了在Android XML布局中设置多选项时遇到的问题,特别是关于点击事件未能正确传递给父级布局的情况,并提供了可能的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_mutil"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
     >

    <LinearLayout 
        android:layout_marginTop="15dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"


        >
   <!--  <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" > -->

        <!--
        android:drawableRight="@drawable/quesion_checkbox_selector" 
        android:button="@null"
        -->

        <CheckBox

                 android:layout_marginLeft="12dp"
            android:layout_marginRight="5dp"
           android:layout_marginTop="1dp"
            android:id="@+id/cb_qustion_body"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:button="@null"
            android:checked="false"
            android:drawableRight="@drawable/quesion_checkbox_selector"
            android:textColor="#696969"
            android:textSize="14sp" />
  <!--   </LinearLayout> -->

   <!--  <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" > -->

        <LinearLayout
            android:id="@+id/ll_qustion_body_controlpic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <ImageView
                android:layout_marginLeft="10dp"
                android:id="@+id/iv_qustion_body"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:scaleType="fitXY"
                android:src="@drawable/personal_head_icon"
                android:visibility="gone" />

            <TextView
                android:id="@+id/tv_qustion_body"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="6dp"
                android:layout_marginLeft="10dp"
                android:text="上海"
                android:textColor="#696969"
                android:textSize="14dp" />
        </LinearLayout>


       <!--  </LinearLayout> -->


    </LinearLayout>
<View 
                  android:layout_width="match_parent"
                  android:layout_height="1dp"
                  android:background="#EFEFEF"


                  />
</LinearLayout>

布局预览图:
这里写图片描述

代码控制(最外层线性布局点击事件):

ll_mutil.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                      Toast.makeText(ctx, "多选,选中", 0).show();
                        mutil_click(MutilTpleQuestOption, cb_qustion_body, ll_mutil);
//                      if (QuestionDetailActivity.submitMap.containsKey(tpleQuestSubject.getSubjectId())) {
//                          if (!positions.contains(position)) {
                                positions.add(position);
//                          }
//                      }
                    }
                });

出问题代码处:

LinearLayout ll_qustion_body_controlpic=(LinearLayout) view.findViewById(R.id.ll_qustion_body_controlpic);
                ImageView iv_qustion_body=(ImageView) view.findViewById(R.id.iv_qustion_body);
                TextView tv_qustion_body=(TextView) view.findViewById(R.id.tv_qustion_body);
                if (canQuest) {
                    ll_qustion_body_controlpic.setEnabled(true);
                    ll_mutil.setEnabled(true);
                    cb_qustion_body.setEnabled(true);
                    ll_qustion_body_controlpic.setClickable(true);
                    ll_mutil.setClickable(true);
                    cb_qustion_body.setClickable(true);
                }else{
                    ll_qustion_body_controlpic.setEnabled(false);
                    ll_mutil.setEnabled(false);
                    cb_qustion_body.setEnabled(false);
                    ll_qustion_body_controlpic.setClickable(false);
                    ll_mutil.setClickable(false);
                    cb_qustion_body.setClickable(false);
                }

布局文件层次
这里写图片描述
这里写图片描述

下面代码 导致: ll_mutil.setOnClickListener 无法接收到事件的传递
 ll_qustion_body_controlpic.setEnabled(true);
 ll_qustion_body_controlpic.setClickable(true);
 ll_qustion_body_controlpic.setEnabled(false);
  ll_qustion_body_controlpic.setClickable(false);
<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值