0

从这个活动我将数据发送到另一个活动

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);
        }
    });
}
}

我的第二个活动是我从意图接收数据并希望在 web 视图中显示它。

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);

}

}

从谷歌上的一些搜索中,我发现它可以通过使用 javascript 变量来完成,但我不知道该怎么做。请回答。

4

2 回答 2

1

你检查过 Android WebView文档吗?

 // 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.
于 2013-05-13T09:18:19.003 回答
0

您可以简单地将数据添加到 webview 中

webview.loadData("your string text", "text/html", null);
于 2013-05-13T09:27:39.653 回答