如何在回收站视图中处理空数据?

时间:2016-06-12 08:11:15

标签: android android-layout android-recyclerview adapter

<android.support.v7.widget.RecyclerView
    android:id="@+id/education_recycle_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>

这是我当前用于循环视图的xml布局文件。

如何在回收站视图中处理空数据? 是否可以将文本显示在同一布局中的“无数据”?

由于

3 个答案:

答案 0 :(得分:3)

我就是这样做的:

在XML中:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<TextView
    android:id="@+id/tv_no_data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/empty_text" 
    android:textAppearance="?android:textAppearanceMedium"
    android:visibility="invisible" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/education_recycle_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    app:layoutManager="LinearLayoutManager" />
</FrameLayout>

Activity

if (!data.isEmpty()) {
                        //if data is available, don't show the empty text
                        emptyText.setVisibility(View.INVISIBLE);
                        RecyclerAdapter adapter = new RecyclerAdapter(data); // pass the data to your adapter here
                        recyclerView.setAdapter(adapter);

                    } else
                        emptyText.setVisibility(View.VISIBLE);

如果您需要更多信息,请与我们联系。

答案 1 :(得分:0)

使用文字&#34创建if(noData) { textview.setVisibility(View.Visible); recylerView.setVisibility(View.Gone); }else{ textview.setVisibility(View.Gone); recylerView.setVisibility(View.Visible); } ;无可用数据&#34;。并在你的java put

$attachment_location = "filePath";
if (file_exists($attachment_location)) {

    header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
    header("Cache-Control: public"); // needed for internet explorer
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: Binary");
    header("Content-Length:".filesize($attachment_location));
    header("Content-Disposition: attachment; filename=filePath");
    readfile($attachment_location);
    die();
} else {
    die("Error: File not found.");
}

答案 2 :(得分:0)

新方法是使用View Flipper

<ViewFlipper
        android:id="@+id/flipper"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_userTaskRecycleView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </android.support.v7.widget.RecyclerView>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:gravity="center"
                android:text="No task found"
                android:textColor="#d3d3d3"
                android:textSize="25sp" />
        </RelativeLayout>
    </ViewFlipper>

然后在活动中检查DataSet是否为空:

if(dataSet.isEmpty()){
viewFlipper.showNext();
//this will automatically show the next layout in the view flipper.

}
else{
// set your adapter here.
}