This example describes the button control usage of Android programming. Share to everyone for your reference, specific as follows:
One, button overview
Android.widget.Button directly inherits from Android.wdiget.TextView.
Direct subclasses are: Compoundbutton.
Indirect subclasses are: Checkbox,radiobutton,switch,togglebutton.
The Button class represents a buttons control. The button control can be pressed or clicked by the user to trigger another action.
Second, the Use of button
A typical usage:
public class MyActivity extends activity {
protected void onCreate (Bundle icicle) {
super.oncreate (icicle);
Setcontentview (r.layout.content_layout_id);
Final button button = (button) Findviewbyid (r.id.button_id);
Button.setonclicklistener (New View.onclicklistener () {public
void OnClick (View v) {
//Perform action on click< c10/>}}
);
}
In addition to binding Onclicklistener for button in the activity class directly, you can bind triggered methods in an XML file by Android:onclick properties.
As an example:
<button
android:layout_height= "wrap_content"
android:layout_width= "Wrap_content"
@string/self_destruct "
android:onclick=" Selfdestruct "/>
Now, when the user presses this button, the system invokes the Selfdestruct (view) method in the activity, in order for this method to work, the method must be public and only one View parameter can be accepted. When the method is invoked, the clicked control is passed into the selfdestruct (view) method as a parameter of the view type. Such as:
public void selfdestruct (view view) {
//Kabloey
}
Three, XML attributes
The XML attribute of the button is basically consistent with the TextView. Interested friends can refer to the site related documents.
Four, common public methods
The common public method for button is basically consistent with TextView.
I hope this article will help you with the Android program.