Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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 延迟后停止拉刷新_Android - Fatal编程技术网

Android 延迟后停止拉刷新

Android 延迟后停止拉刷新,android,Android,我想在延迟后停止拉刷新,所以我这样做了,但不起作用: final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) rootview.findViewById(R.id.activity_main_swipe_refresh_layout); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListene

我想在延迟后停止拉刷新,所以我这样做了,但不起作用:

   final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) rootview.findViewById(R.id.activity_main_swipe_refresh_layout);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override public void run() {
                        mSwipeRefreshLayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });
    }
下面是XML代码,我不知道它是否好:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"

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


<android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:id="@+id/activity_main_swipe_refresh_layout"
    >

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@id/android:list"
        android:longClickable="true"





        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true" />



    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:textSize="30sp"


        android:text="" />


    <com.getbase.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/semi_transparent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_plusIconColor="@color/primaryTextColor"
        fab:fab_colorNormal="@color/primaryColor"
        fab:fab_colorPressed="@color/AccentColor"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView5"
        android:height="200dp"
        android:width="200dp"
        android:visibility="gone"
        android:textSize="22dp"
        android:text="Vous n&apos;avez aucun coffy commencez par en ajouter un en cliquant sur le bouton +"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <WebView
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:id="@+id/webView3"
        android:visibility="invisible"
        android:layout_above="@+id/semi_transparent"
        android:layout_centerHorizontal="true" />

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




</RelativeLayout>

我没有发现您的代码中有任何错误,但您可以检查此剪报:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);

    SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    swipeLayout.setOnRefreshListener(this);
    swipeLayout.setColorScheme(android.R.color.holo_blue_bright, 
            android.R.color.holo_green_light, 
            android.R.color.holo_orange_light, 
            android.R.color.holo_red_light);
}


@Override public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
            swipeLayout.setRefreshing(false);
        }
    }, 5000);
}
我认为你的布局是错误的,相对的你应该在布局里面。检查下面的布局,注意如果仍然不起作用,可以将xmlns:fab=”http://schemas.android.com/apk/res-auto“要更改布局属性,请执行以下操作:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@id/android:list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:longClickable="true"/>

        <TextView
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text=""
            android:textSize="30sp"/>

        <com.getbase.floatingactionbutton.AddFloatingActionButton
            android:id="@+id/semi_transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            fab:fab_colorNormal="#ABCDEF"
            fab:fab_colorPressed="@color/AccentColor"
            fab:fab_plusIconColor="@color/primaryTextColor"/>
        <TextView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:width="200dp"
            android:height="200dp"
            android:text="Vous n&apos;avez aucun coffy commencez par en ajouter un en cliquant sur le bouton +"
            android:textSize="22dp"
            android:visibility="gone"/>

        <WebView
            android:id="@+id/webView3"
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_above="@+id/semi_transparent"
            android:layout_centerHorizontal="true"
            android:visibility="invisible"/>
    </RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>


是的,但它是在一个片段中,所以有点不同。它仍然不起作用。不明白出了什么问题。你能发布xml布局吗。它可能会有所帮助。它仍然不起作用。可能我对处理程序的导入不好。请参阅我的更新答案
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <RelativeLayout
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@id/android:list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:longClickable="true"/>

        <TextView
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text=""
            android:textSize="30sp"/>

        <com.getbase.floatingactionbutton.AddFloatingActionButton
            android:id="@+id/semi_transparent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            fab:fab_colorNormal="#ABCDEF"
            fab:fab_colorPressed="@color/AccentColor"
            fab:fab_plusIconColor="@color/primaryTextColor"/>
        <TextView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:width="200dp"
            android:height="200dp"
            android:text="Vous n&apos;avez aucun coffy commencez par en ajouter un en cliquant sur le bouton +"
            android:textSize="22dp"
            android:visibility="gone"/>

        <WebView
            android:id="@+id/webView3"
            android:layout_width="10dp"
            android:layout_height="10dp"
            android:layout_above="@+id/semi_transparent"
            android:layout_centerHorizontal="true"
            android:visibility="invisible"/>
    </RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>