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

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函数

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

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配