2013-05-13 57 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); 
相關問題