Home > Android > Android Radio Button | Snippet | Source Code

Android Radio Button | Snippet | Source Code

Android Radio Button Example

 Android Radio Button 

Android Radio Button Example:

Android Radio Button Example       Android Radio Button Example

Java Code(RadioAct)

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

public class RadioAct extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress);
}
public void display(View v)
{
RadioButton rb = (RadioButton)v;

String text = rb.getText().toString();

Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
public void view1(View v)
{
Intent i=new Intent(this,RadioNext.class);
startActivity(i);
}

}

Layout XML Code(activity_progress)

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”.RadioAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:layout_gravity=”center”
android:textStyle=”bold”
android:text=”RADIO BUTTON”
android:layout_marginBottom=”120dp” />

<RadioGroup
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:orientation=”vertical”
android:id=”@+id/rg1″
android:layout_gravity=”center”
android:layout_marginBottom=”100dp”>

<RadioButton
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/rb1″
android:onClick=”display”
android:text=”Yes”/>

<RadioButton
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/rb2″
android:onClick=”display”
android:text=”No”/>

<RadioButton
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/rb3″
android:onClick=”display”
android:text=”Maybe”/>
</RadioGroup>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>



Output

Android Radio Button Example  Android Radio Button Example

Download Source Code

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 


[metaslider id=3165]

Recent   

Android Radio Button Example

Is this Useful content For You?