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 ?
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;
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.