Issue
Suppose we want to make a button do something , we may use onClick event or onClickListener
While using onClick Event in XML file , we input a method name. Where does the method have to be located ?
Solution
Inside the activity class where the xml layout is inflated.
It has to be public
with this signature:
public void doSomething(View v) {
//..........
}
In the xml of the activity, the attribute set to the Button
must be:
android:onClick="doSomething"
The v
parameter is actually the View
that triggered this event,
in your case a Button
and you can access it by:
Button button = (Button) v;
Answered By - forpas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.