如何将数据从活动发送到该活动本身中的Web视图? [英] How to send data from activity to a webview in that activity itself?

查看:91
本文介绍了如何将数据从活动发送到该活动本身中的Web视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过此活动将数据发送到另一个活动

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final EditText etxt=(EditText)findViewById(R.id.editText1);
            final EditText etxt1=(EditText)findViewById(R.id.editText2);
    Button btn=(Button)findViewById(R.id.button1);
    btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String s= etxt.getText().toString();
                            String s1= etxt1.getText().toString();
            Intent intent= new Intent(getApplicationContext(),WebActivity.class);
            intent.putExtra("key", s);
                            intent.putExtra("key1", s1);
        }
    });
}
}

我的第二项活动是从意图中接收数据,并希望将其显示在网络视图中.

public class WebActivity extends Activity {
WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webpage);
    Bundle b = getIntent().getExtras();
    String s = b.getString("key");
            String s1=b.getString("key1");
    webView=(WebView)findViewById(R.id.webview);

}

}

在Google上进行的一些搜索中,我发现可以使用javascript变量来完成此操作,但我不知道该怎么做.请回答.

From some searching on Google i found that it can be accomplished by using javascript variables but I dont know how to do it. Kindly answer.

推荐答案

您是否检查过Android

Did you checked Android WebView documentation?

 // Simplest usage: note that an exception will NOT be thrown
 // if there is an error loading this page (see below).
 webview.loadUrl("http://slashdot.org/");

 // OR, you can also load from an HTML string:
 String summary = "<html><body>You scored <b>192</b> points.</body></html>";
 webview.loadData(summary, "text/html", null);
 // ... although note that there are restrictions on what this HTML can do.
 // See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.

这篇关于如何将数据从活动发送到该活动本身中的Web视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆