How to use Javascript in Textview?

Asked

Viewed 33 times

1

I have a Webview that accesses a certain site, I need to recover a value using javascript getElementById and pass this value to a Textview, how can I perform this procedure ? Follows the code:

public class Inicio extends AppCompatActivity {

    TextView recuperarvalor;
    WebView site;

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

        recuperarvalor = (TextView) findViewById(R.id.idtextview);
        site = (WebView) findViewById(R.id.idwebview);

        site.loadUrl("https://nomedosite");

        WebSettings settings = site.getSettings();

        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.supportZoom();
        settings.setBuiltInZoomControls(true);

        settings.setTextZoom(150);
        settings.setSupportZoom(true);
        settings.setDomStorageEnabled(true);

        site.loadUrl("javascript:var x = document.getElementById('live_bid');");
        site.setWebViewClient(new WebViewClient() {
            @Override
            public void onLoadResource(WebView view, String url) {
                super.onLoadResource(view, url);
                site.loadUrl("javascript:var x = document.getElementById('live_bid');");
recuperarvalor.setText("QUERO OBTER O VALOR DO CAMPO DO SITE AQUI");

            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.