如何从片段隐藏Recycleview的行项目 [英] How to Hide the row item of Recycleview from fragment

查看:80
本文介绍了如何从片段隐藏Recycleview的行项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段类,它使用Recycleview显示文本"和图像"列表. 如何访问Recycleview行项目并将自定义文本设置为任何Textview或隐藏片段类中的所需Textview.

I have a fragment class which uses Recycleview to show list of Text and Image. How can I access Recycleview row items and set an custom text to any Textview or Hide the Desired Textview from fragment class.

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingBottom="4dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="4dp">
<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" />

  <include
    android:id="@+id/include_tag"
    layout="@layout/row_item"/>
 </FrameLayout>

并且我的行项目布局为

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res   /android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent">

    <TextView
        android:id="@+id/flower_Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textStyle="bold"
        android:maxLines="1"
        android:layout_centerInParent="true"
        android:gravity="center_vertical|center_horizontal"
        android:textAlignment="center"
        android:textColor="#E91E63"
        android:fontFamily="sans-serif-condensed"
        android:text="Sagar Rawal"/>

            <TextView
                android:layout_marginTop="8dp"
                android:id="@+id/flower_details"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="14sp"
                android:textStyle="bold"
                android:maxLines="3"
                android:textColor="#673AB7"
                android:text="This Text need to Be Change "/>



</RelativeLayout>

和我的Fragment类

and my Fragment class i s

 public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
   final View view = inflater.inflate(R.layout.activity_main, container, false);



    View test1View = view.findViewById(R.id.include_tag);
    mhideText = (TextView) test1View.findViewById(R.id.flower_details);
    mhideText.setVisibility(View.INVISIBLE);

return view;

但是它不起作用.并且Textview仍然可见.

But it doesn't work. and Textview is still Visible.

请帮助.预先感谢.

推荐答案

尝试执行此操作:

rowview = inflater.inflate(R.layout.row_item, container, false);
mhideText = (TextView)rowview.findViewById(R.id.flower_details);
mhideText.setVisibility(View.INVISIBLE);

这篇关于如何从片段隐藏Recycleview的行项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆