Sabtu, 09 Juni 2012

Button in android

Button demo

  • Button in android mostly used to get action from user.
  • You can get action from button in onClick() event.
  • In android button works same as it works in java.
  • Two ways to create Button in android
    • Using xml file in layout

               <Button
              android:id="@+id/button1"
              android:layout_width="
      wrap_content"
              android:layout_height="wrap_content"
              android:text="My Button"/>

       
    • Using java code in activity class
             
               Button btnDynamic = new Button(this);
              btnDynamic.setText("Dynamically created Button");
  • Types of Button in android
    • Button
       
    • ToggleButton
      • <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="77dp"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />
         
    • ImageButton
      • <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/gtumcaicon" >
         
    • CheckBox
      • <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select" >
         
    • RadioButton
      • <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
              <RadioButton
           android:id="@+id/red"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Red" />

           <RadioButton
           android:id="@+id/green"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="Green" />
        </
        RadioGroup>

Tidak ada komentar:

Posting Komentar