Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SwipeRefreshLayout,带有RecyclerView empty和TextView_Android_Fragment_Android Recyclerview_Swiperefreshlayout - Fatal编程技术网

Android SwipeRefreshLayout,带有RecyclerView empty和TextView

Android SwipeRefreshLayout,带有RecyclerView empty和TextView,android,fragment,android-recyclerview,swiperefreshlayout,Android,Fragment,Android Recyclerview,Swiperefreshlayout,我的问题在这里得到了完美的解释,并与在SwiperFreshLayout中处理emtpy recyclerview有关。解决方案就在这个链接中,但我不知道如何实现它 这是我的密码 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" androi

我的问题在这里得到了完美的解释,并与在SwiperFreshLayout中处理emtpy recyclerview有关。解决方案就在这个链接中,但我不知道如何实现它

这是我的密码

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                              android:id="@+id/swipeRefresh"
                                              android:layout_width="match_parent"
                                              android:layout_height="match_parent">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/background"
            android:id="@+id/rv"
            xmlns:android="http://schemas.android.com/apk/res/android"/>

        <TextView
            android:id="@+id/empty_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:visibility="gone"
            android:text="No hay conexión con el servidor" />
    </FrameLayout>

</android.support.v4.widget.SwipeRefreshLayout>

这是我的片段,我不能扩展另一个类,因为我已经扩展了片段

public class FragmentNoticias extends Fragment {

    private RVAdapter adapter;
    private String mNoticias = "Resumen";
    private SwipeRefreshLayout refreshLayout;
    private Cursor cursor;

    public interface RefreshCall {

        boolean onMethodRefreshCall();
    }

    private RefreshCall mRefreshCall;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        cursor = FeedDatabase.getInstance(getActivity()).obtenerEntradas(mNoticias);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);

        View root = inflater.inflate(R.layout.recycler_view, container, false);
        RecyclerView rv = (RecyclerView) root.findViewById(R.id.rv);

        rv.setHasFixedSize(true);

        //hace que el RecyclerView se muestre por defecto con un layout linear
        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        rv.setLayoutManager(llm);

        adapter = new RVAdapter(
                getActivity(),
                cursor);
        rv.setAdapter(adapter);


        // Obtener el refreshLayout
        refreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipeRefresh);

        refreshLayout.setColorSchemeResources(
                R.color.s1,
                R.color.s2,
                R.color.s3
        );

        // Iniciar la tarea asíncrona al revelar el indicador
        refreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        new HackingBackgroundTask().execute();
                    }
                }
        );

        try {
            this.mRefreshCall = ((RefreshCall) getActivity());
        } catch (ClassCastException e) {
            throw new ClassCastException("Activity must implement AdapterCallback.");
        }


        return root;
    }

    private class HackingBackgroundTask extends AsyncTask<Void, Void, Cursor> {...}
公共类fragmentNotifias扩展了Fragment{
专用适配器;
私有字符串mNoticias=“Resumen”;
私人交换机布局刷新布局;
私有游标;
公共接口刷新调用{
布尔onMethodRefreshCall();
}
私人刷新呼叫mRefreshCall;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
cursor=FeedDatabase.getInstance(getActivity()).obtenerEntradas(mNoticias);
}
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
super.onCreateView(充气机、容器、保存状态);
视图根=充气机。充气(R.layout.recycler\u视图,容器,假);
RecyclerView rv=(RecyclerView)root.findViewById(R.id.rv);
rv.setHasFixedSize(真);
//回收站的位置应符合线性布局
LinearLayoutManager llm=新的LinearLayoutManager(getActivity());
rv.setLayoutManager(llm);
适配器=新适配器(
getActivity(),
光标);
rv.设置适配器(适配器);
//奥本纳平面布置图
refreshLayout=(SwipeRefreshLayout)root.findViewById(R.id.swipeRefresh);
refreshLayout.setColorSchemeResources(
R.color.s1,
R.color.s2,
R.color.s3
);
//印度狂欢节
refreshLayout.setOnRefreshListener(
新建SwipeRefreshLayout.OnRefreshListener(){
@凌驾
公共void onRefresh(){
新建HackingBackgroundTask().execute();
}
}
);
试一试{
this.mRefreshCall=((刷新调用)getActivity());
}catch(ClassCastException e){
抛出新的ClassCastException(“活动必须实现AdapterCallback”);
}
返回根;
}
私有类HackingBackgroundTask扩展异步任务{…}
我应该如何实现链接的解决方案以在片段中使用它?我很困惑

编辑


由于第一个答案,它可以工作,但是刷新圈动画还没有正确显示。

代替android.support.v4.widget.SwipeRefreshLayout在布局中使用
yourpackagename.SwipeRefreshLayoutWithEmpty

(将
yourpackagename
替换为
SwipeRefreshLayoutWithEmpty
类的路径)。

除了sJy答案之外,您还应该在片段中替换:

private SwipeRefreshLayout refreshLayout;
with
private SwipeRefreshLayout with Empty refreshLayout;


尝试在布局文件中使用SwiperFreshLayoutWithEmpty而不是SwiperFreshLayout。黑客背景任务,好名字!为什么不将visible(Goe)设置为recycler view,并将setvisible(visible)设置为visible(visible)当对HackingBAckgroundTask的调用为空时显示文本视图?@mhkore你能具体告诉我你想在上面的问题中实现什么吗?@Amit具体是:我调用我的数据库->如果为空->而不是recyclerview我显示一个文本视图“无数据连接”->一旦我刷新并且我的数据库已满->显示带有项目的recyclerview
refreshLayout.setOnRefreshListener(
                new SwipeRefreshLayout.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        new HackingBackgroundTask().execute();
                    }
                }
        );
refreshLayout.setOnRefreshListener(
                new SwipeRefreshLayoutWithEmpty.OnRefreshListener() {
                    @Override
                    public void onRefresh() {
                        new HackingBackgroundTask().execute();
                    }
                }
        );