简体   繁体   English

如何在 android 的单个片段中隐藏回收器视图的视图(但在两个片段中使用相同的列表)

[英]How to hide a view of recycler view in a single fragment in android (But using same list in two fragments)

I am using a recycler view in two fragments.我在两个片段中使用回收站视图。

But one of the fragments needs not to show a particular view.但是其中一个片段不需要显示特定的视图。 But Need to show all the views in another screen.但需要在另一个屏幕上显示所有视图。

How can I hide that particular view alone in one of my fragment如何在我的一个片段中单独隐藏该特定视图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearlayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:background="@drawable/corner_radius"
        />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:orientation="vertical">
        <TextView
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="left"
            android:foregroundGravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:textColor="@color/white_new"
            android:textSize="20dp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="left"
            android:foregroundGravity="center_horizontal"
            android:layout_marginLeft="10dp"
            android:textColor="@color/gray"
            android:textSize="18dp"/>

    </LinearLayout>
</LinearLayout>
    <View style="@style/Divider.Horizontal.Gray" android:id="@+id/divider"  android:layout_marginTop="10dp" android:layout_marginBottom="10dp"/>
</LinearLayout>

Why not you use if condition for this or为什么不为此使用 if 条件或

yourAdapter(isoneFramgent:Boolean){

}

send true and false from your fragment if its from first fragment send true and its from second fragment send false and add a if condition into bindView to show and hide your view according to fragment如果从第一个片段发送 true 和从第二个片段发送 false 则从您的片段发送 true 和 false 并将 if 条件添加到 bindView 以根据片段显示和隐藏您的视图

Filter your data source before setting it to adapter and pass the filtered data to one fragment and raw data to other fragment.在将数据源设置为adapter之前过滤您的数据源,并将过滤后的数据传递给一个fragment ,将原始数据传递给另一个片段。

Suppose you have list of strings假设您有字符串列表

val originalData = listOf("data") //this is your raw list
//Fragment 1
  val f1Data = ArrayList(originalData.filter{ //filter one item })
  val f1Adapter = YourAdapter(f1Data)
//Fragment 2
  val f2Adapter = YourAdapter(originalData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM