Android Buttons

In xml:

 <Button
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/self_destruct"
     android:onClick="selfDestruct"/>

In Java code:

 public class MyActivity extends Activity{
     protected void onCreate(Bundle icicle){
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         finalButton button =(Button) findViewById(R.id.button_id);
         button.setOnClickListener(newView.OnClickListener(){
             publicvoid onClick(View v){
                 // Perform action on click
             }
         });
     }
 }
Advertisements

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s