当我的“回收者”视图的过滤器中没有结果时,我想显示一条消息。因此,我有一个固定的文本(在string.xml中)默认情况下隐藏在回收站视图的后面,我想在没有过滤器结果但我无法显示它时显示它,我使用的代码不起作用。
app_bar_main.xml中的LinearLayout中有“隐藏”文本(这是我显示/隐藏的视图,取决于过滤结果)
<LinearLayout
android:id="@+id/layoutFilterNotFound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:elevation="-100dp"
android:visibility="invisible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="30sp"
android:layout_margin="10dp"
android:textStyle="bold"
android:textColor="@color/gris"
android:text=":(\nNo data"/>
</LinearLayout>
我用来管理它的代码如下:
public void showNoFilterText() {
if (!activar){
View appbarMainScreen = inflater.inflate(R.layout.app_bar_main, null);
LinearLayout layoutToShow = appbarMainScreen.findViewById(R.id.layoutFilterNotFound);
layoutToShow.setVisibility(View.VISIBLE);
}
}
答案 0 :(得分:0)
我看到您在另一版式中有此文字。如果此“空视图”仅包含文本,我想您可以将TextView添加到具有回收者视图的布局中。然后,如果没有项目,您将只需要隐藏回收站并显示TextView。
如果要在单独的布局中使用它,则必须include
在具有列表(https://developer.android.com/training/improving-layouts/reusing-layouts)的布局中。保持变化的可见性保持不变