AndromedaF小胖鹿 2020-05-04 21:47 采纳率: 100%
浏览 644
已采纳

LinearLayout中 Textview要点击两次才实现点击事件?

LinearLayout中 Textview点击两次才实现点击事件

我想做一个展开收起的功能 我用的是 Textview来显示展开和收起的工作

现在的效果是 要点击两次在会出现展开功能 点完一次展开收起后 可正常点击展开收起

试过在展开的TextView框中加入
android:focusableInTouchMode="false"
android:duplicateParentState="true"
android:focusable="false"

都没什么效果
个人基础不是很好 不知道是哪方面出现了问题 还请各位帮忙看看 谢谢啦

这个xml布局代码
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/showall"
            android:layout_width="@dimen/x580"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

        <TextView
            android:id="@+id/tv_jiexi1"
            android:layout_width="@dimen/x580"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/x33"
            android:layout_marginRight="@dimen/x_100"
            android:text="解析"
            android:textColor="@color/color_text"
            android:textSize="@dimen/x28" />

    </LinearLayout>

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

            <TextView
                android:id="@+id/tv_more"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/x33"
                android:layout_marginLeft="@dimen/x1"
                android:text="展开"
                android:textColor="@color/color_text"
                android:textSize="@dimen/x28"          
                />
        </LinearLayout>

    </LinearLayout>

            这是适配器页面的实现代码


   @BindView(R.id.tv_more)
    TextView tvMore;
    @BindView(R.id.showall)
    LinearLayout tvShowAll;

             holder.tvMore.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v)
        {

            if(holder.tvMore.getText()=="展开")
            {
                holder.tvShowAll.setVisibility(View.VISIBLE);
                holder.analyze.setText("解析:" + list.get(position).getAnalyze());
                holder.tvMore.setText("收起");

            }
            else{
                holder.tvShowAll.setVisibility(View.VISIBLE);
                holder.analyze.setText("解析:" + list.get(position).getAnalyze().substring(0,20));
                holder.tvMore.setText("展开");
            }
        }
    });
  • 写回答

1条回答 默认 最新

  • 键盘舞者113 博客专家认证 2020-05-05 11:56
    关注

    代码写错了,String的值不能用==去判断,需要用equals函数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格