How to close a WebView automatically after a certain event (Android)?

0

I am working with TypeForm forms that I show them through WebView in my application.

What I'm trying to do is close the WebView after they finish the form.

When the form is completed on the screen, a text appears thanking. How can I take that text and in the case that appears close the WebView.

This is the code I have made.

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle("");

    Bundle datos = this.getIntent().getExtras();
    assert datos != null;
    user = datos.getString("email");

    WebView myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());

    if (Locale.getDefault().getLanguage().equals("en")) {

        myWebView.loadUrl("http://cliente.typeform.com/to/U0mcRV?user=" + user);
    }else{

        myWebView.loadUrl("http://cliente.typeform.com/to/U7o3PU?user=" + user);
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();
        return true;
    } else
        return super.onOptionsItemSelected(item);

}

Greetings!

    
asked by FabriC 03.12.2017 в 16:46
source

1 answer

0

What you can do in this case is to change the visibility of the WebView to "close it", when you detect the completion of the form, do this to make it disappear:

myWebView.setVisibility(View.GONE);

and this to appear:

myWebView.setVisibility(View.VISIBLE);
    
answered by 05.12.2017 в 20:40