2013-05-13 59 views
0

从这个活动,我将数据发送到另一个活动如何将活动中的数据发送到该活动本身的webview?

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变量来实现,但我不知道该怎么做。请回答。

回答

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. 
+0

假设添加在web视图数据,我想送JSON数据的WebView呢? – 2013-05-13 09:28:47

+0

String summary =“ YOUR JSON HERE”; webview.loadData(summary,“text/html”,null);感谢... – 2013-05-13 09:29:58

+0

...以及如何在webview中查看数据? – 2013-05-13 09:39:04

0

只需通过

webview.loadData("your string text", "text/html", null); 
相关问题