Don't use onClick
on XML, as it's buggy and may not work on all versions:
Buttons onClick Force closes app on Android 4.1 device
Better do it in code:
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// code here
}
});
In xml,make sure you declared onClick
in your Button
attribute
android:onClick="cli"
Also, in onCreate
, declare your Button
id
Button button = (Button) findViewById(R.id.button);
Don't use onClick
on XML.
Use OnClickListeners
. Here is the code:
Button button = findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
cli(v);
}
});
The above code will help you with detecting clicks on the button. Prefer not using android:onClick
in XML.
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.