@codingpan
2015-05-13T16:19:58.000000Z
字数 613
阅读 782
android
mobile
//In your view xml file, set the onClick property
android:id="@+id/button1"
android:onClick="someMethod"
//In your Activity, write the implementation of someMethod
public void someMethod(View v) {
int id = v.getId();
if (id == R.id.button1) {
//Do sth to response click event
}
}
Button btn = (Button) findViewById(R.id.mybutton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
someMethod(v);
//or Do sth
}
});
// some more code
public void someMethod(View v) {
// does something very interesting
}