I am trying to open the URL entered by user but clicking on the button the app is not responding.
The Java Snippet of What i have done is :-
e=(EditText) findViewById(R.id.editText);
final String s=e.getText().toString();
browser = (Button) findViewById(R.id.button2);
browser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(s));
startActivity(i);
}
});
You initialised s
when EditText was empty. So add below line in OnClick() method to get user input-
String s=e.getText().toString();
browser = (Button) findViewById(R.id.button2);
browser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s=e.getText().toString();
Intent i = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse(s));
startActivity(i);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.