Wednesday 20 February 2013

how to creating Basic Button in android


Step for creating Basic Button
- Start new Android application
- Go to Main.axml and make following changes


main.xml:
   
 <?xml version="1.0" encoding="utf-8"?>
<
LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<
Button 
    
android:id="@+id/MyButton"
    android:layout_width="fill_parent"
    
android:layout_height="wrap_content"     
    />
</
LinearLayout>


 -Go to Activity1.cs class make following changes
 

 Activity1 .cs

    public class Activity1 : Activity
    {
        
int count = 1;

        
protected override void OnCreate(Bundle bundle)
        {
            
base.OnCreate(bundle);
             

            SetContentView(Resource.Layout.Main);
           

            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += 
delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }

 
As above we create a simple button and create a button click event for it when you click on the button it will count the click and display to the user
Run the application

 

No comments:

Post a Comment