Tuesday, 20 June 2017

Easiest way to use onClick method in Android. 

It can be done by using the XML. Just define a Button with 'id' and and 'onClick'.

Like: 
<Button 
android: height = "wrap_content"
android: height = "wrap_content"
android: text = "Click it"
android: id = "@id/click_button_1"
android: onClick = "Do_the_Click"
/>

So when you will define the onClick, there will be a suggestion on the left side of the statement. Click on that, it would suggest to make a method in java file with name "Do_the_Click", Click on it and it will create it.

And then you can write your code in that method. 

No comments:

Post a Comment