Can anybody tell how to add a button in android?
+1
A:
Check this Android Button tutorial; this simple example creates a Close Button.
All you need to do is:
1.Add Button widget to your Layout
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
2.Attach a setOnClickListener method to the button instance:
protected void onCreate(Bundle savedInstanceState) {
this.setContentView(R.layout.layoutxml);
this.closeButton = (Button)this.findViewById(R.id.close);
this.closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
systempuntoout
2010-04-21 09:27:53
hi,is it possible to add a button without declaring it in the layout xml file?
poeschlorn
2010-05-11 12:34:42