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 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据