I have created some buttons in XML and I have method that will onClick open a URL. How do I link this method to my button so that on tap/onClick it will call the method.
Here's the method code:
public void openResource() {
Uri uri = Uri.parse("http://librarywales.org");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
And I have created an instance of my XML Button in the onCreate method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button libButton = (Button) findViewById(R.id.button1);
}
How do I add that method to the libButton instance?
I have now solved the above issue with the help of 'vins' but when I run this application on the AVD and click on a button it pops up with an android message box saying. 'Unfortunately, ApplicationName has stopped working.'
Anyone know why this is?
Thanks, Dan