SwipeRefreshLayout问题使用emptyView和ListView当 [英] SwipeRefreshLayout Issues When Using emptyView and ListView

查看:327
本文介绍了SwipeRefreshLayout问题使用emptyView和ListView当的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是围绕一个ListView包裹SwipeRefreshLayout。当ListView控件是空的,我给自己定一个TextView出现。这个作品很好,但是当ListView控件是空的,空的观点显示,在SwipeRefreshLayout不显示正确。如果向下拖动,没有圈下来,但是当你松开手指圈闪烁在屏幕上,然后消失。如果你只是触摸屏幕的任何地方,其实SwipeRefreshLayout会出现在相同的方式。下面是我如何我的XML定义它:

I'm using a SwipeRefreshLayout wrapped around a ListView. When the ListView is empty, I've set a TextView to appear. This 'works' fine, but when the ListView is empty and the empty view is showing, the SwipeRefreshLayout doesn't display right. If you drag down, no circle comes down but when you release your finger the circle flashes on the screen and then disappears. If you just touch the screen anywhere, in fact, the SwipeRefreshLayout will appear in the same fashion. The following is how I've defined it in my XML:

<FrameLayout
    android:id="@+id/empty_view_requests"
    android:layout_width="match_parent"
    android:layout_centerInParent="true"
    android:layout_below="@+id/appbar"
    android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbar"
        android:id="@+id/buddy_requests_swipe_layout">
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/buddy_requests_listview"
            android:layout_gravity="center_horizontal|top"
            />
    </android.support.v4.widget.SwipeRefreshLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="24sp"
        android:layout_gravity="center_horizontal|center_vertical"
        android:id="@+id/norequests_textview"
        android:text="No buddy requests."/>
</FrameLayout>

编辑:活动code

swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.buddy_requests_swipe_layout);
    swipeRefreshLayout.setColorSchemeResources(R.color.lb_green, R.color.lb_orange, R.color.lb_purple);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            VolleyBuddies.makeGetBuddyRequestsAPICall(BuddyRequestsActivity.this, BuddyRequestsActivity.this);
        }
    });
    FrameLayout noRequestsLayout = (FrameLayout)findViewById(R.id.empty_view_requests);
    ListView requestsListView = (ListView)findViewById(R.id.buddy_requests_listview);
    requestListAdapter = new BuddyRequestsActivityListAdapter(this, this);
    requestsListView.setAdapter(requestListAdapter);
    requestsListView.setEmptyView(noRequestsLayout);

我该如何解决这个问题?

How can I fix this?

推荐答案

我粘贴工作code我所面临的问题。希望这将你的作品。
 初步确定emptyview知名度View.GONE.and然后在API调用响应回调,如果没有项目/状态code..etc,setvisibility View.VISIBLE并将其设置为emptyviewfor列表视图。

I am pasting working code of mine.Even I have faced the issues. hope this will works for you. Initially set the emptyview visibility View.GONE.and then on the API Call response callBacks, if there are no items/statuscode..etc ,setvisibility View.VISIBLE and set it as emptyviewfor listview.

findViewById(R.id.lvemptyview).setVisibility(View.GONE);



    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
             if (Utils.isInternetConnected(getApplicationContext())) {
                        CallAPICall(lat, lng);
                        mSwipeRefreshLayout.setRefreshing(false);
                    } }});

这是凌空响应回调

 mSwipeRefreshLayout.setRefreshing(false);

            if (statuscode== 200) {
                try {

                    String content = new String(arg2, "UTF-8");
                    MemberResp memberResp;
                    Gson gson = new Gson();
                    Type type = new TypeToken<MemberResp>() {
                    }.getType();
                        memberResp = gson.fromJson(content, type);
                        if (memberResp.Status == 1) {

                            if (memberResp.bar_lists.size() > 0) {
                                      findViewById(R.id.lvemptyview).setVisibility(View.GONE);
                          setadapter();
                  } else {

               Adapter.ClearAll();
                          findViewById(R.id.lvemptyview).setVisibility(View.VISIBLE);
                             lvList.setEmptyView(findViewById(R.id.lvemptyview));


                            }

这篇关于SwipeRefreshLayout问题使用emptyView和ListView当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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