问题描述
- 如何获取 edittxt 中的值,再放入 URL 中
-
private Button btnLogin; private EditText txtPub; private EditText txtPriv; final Context context = this; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loginfirst); btnLogin = (Button)findViewById(R.id.btnEnter); btnLogin.setOnClickListener(this); txtPub = (EditText)findViewById(R.id.textPublic); txtPriv = (EditText)findViewById(R.id.textPrivate); } @Override public void onClick(View arg0) { Intent intent = new Intent(context, WebViewActivity.class); startActivity(intent); }
WebViewActivity.class
private WebView webView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); webView = (WebView) findViewById(R.id.web_view); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl("http://url.com/txtpub+txtprive"); }
如何获取 edittxt txtpub 和 txtpriv 的值,然后放进url的webviewactivity类中?我想把txtpub 和txtpriv 的值放入url中,怎么实现呢?
解决方案
String txtpubStr=txtPub.getText().toString();
Intent intent = new Intent(context, WebViewActivity.class);
intent.putExtra("txtPub", txtpubStr)
startActivity(intent);
然后在WebViewActivity中
Intent intent=getIntent();
String txtPub=intent.getStringExtra("txtPub")//注意这里的"txtPub"与之前的要一致
时间: 2024-11-18 17:16:37