I have two activity MainActivity.java and WebViewActivity.java in MainActivity there is a edittext and a button. Now i want if i enter any string in edittext and after button click it should pass that string into url in WebViewActivity like www.mywebsite.com+getTestFromEdittext
MainActivity.java
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText inputUrl = (EditText) findViewById(R.id.editText1);
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
startActivity(intent);
}
});
}
}
WebViewActivity.java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.php);
WebView wb = (WebView)findViewById(R.id.webview);
wb.loadUrl("http://example.com" + getStringFromEdittext);
wb.getSettings().setJavaScriptEnabled(true);
}
}
Use this code while starting activity:
MainActivity :
To fetch the value :
WebViewActivity :