Why the page is not updated and the swipe starts working from any scroll position, and not at the very top.

xml

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

java

 import android.os.Handler; import android.net.Uri; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebView; public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { private SwipeRefreshLayout mSwipeLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webView = (WebView) findViewById(R.id.webView); webView.setVerticalScrollBarEnabled(false); webView.setHorizontalScrollBarEnabled(false); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setSupportZoom(false); webView.getSettings().setSupportMultipleWindows(false); Uri data = getIntent().getData(); webView.loadUrl("http://google.com"); mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe); mSwipeLayout.setOnRefreshListener(this); mSwipeLayout.setColorSchemeResources( R.color.blue_swipe, R.color.green_swipe, R.color.orange_swipe, R.color.red_swipe); } @Override public void onRefresh() { new Handler().postDelayed(new Runnable() { @Override public void run() { // stop refresh mSwipeLayout.setRefreshing(false); } }, 3000); } } 

    1 answer 1

    The page is not updated because You do not update it. In the onRefresh method, you need to actually start the update, and not just stop the download animation after 3s.

    The problem is with the appearance of the download indicator in any place, try to solve by setting the height for the WebView content and wrapping the last one in NestedScrollView

    • It is necessary to put onCreate in onRefresh so there were errors - steep
    • @steep, try to reformulate - I do not understand what you want to say - YuriiSPb
    • How to run an update in onRefresh? - steep
    • @steep, just call webView.loadUrl("http://google.com"); again webView.loadUrl("http://google.com"); - Yuriy SPb
    • wherever I put it everywhere is a mistake - steep