我已经实现了SwipeRefreshLayout,它基本上运行良好。https://developer.android.com/training/swipe/add-swipe-interface.html
当你进入列表的底部,当你试图滚动到顶部时,SwipeRefreshLayout刷新时,我面临着魏瑞德的问题。
这不是我需要的。我只需要滚动到列表顶部,而不刷新列表视图。
我的意思是,根据我们的立场,什么时候该重新振作是有条件的。正确的?因为预期的行为是当我们在listview的顶部时允许刷新。
请帮忙。

<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">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >

    <SearchView
        android:id="@+id/editSearch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:iconifiedByDefault="false"
        android:queryHint="Input the number"
        />
<ListView
    android:paddingTop="5dp"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"   />

</LinearLayout>

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

还有密码
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_fragment_two, container, false);

        swiperefresh = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh);
        swiperefresh.setColorScheme(R.color.colorPrimary, R.color.colorAccent, R.color.colorPrimaryDark, R.color.colorPrimary);
        swiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                swiperefresh.setRefreshing(true);
                Log.d("Swipe", "Refreshing Number");
                // Get data from WebAPI or database cache
            }
        });

        return view;
    }

最佳答案

好。。。最后我在这里找到了解决方案Scroll up does not work with SwipeRefreshLayout in Listview
所以我的布局不会改变,但代码是的。
我们要做的是
像public一样实现
AbsListView.OnScrollListener
添加实现接口的两种方法class FragmentTwo extends ListFragment implements SearchView.OnQueryTextListener, AbsListView.OnScrollListener
就像这里

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            swiperefresh.setEnabled(firstVisibleItem == 0);
}

这里的钥匙是
AbsListView.OnScrollListener
implements OnScrollListener inside listFragment

10-07 17:43