RadioButton in Android

RadioButton in Android

RadioButton in Android

Radiobutton Screen shot

 

 

Radiobutton.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”
tools:context=”.MainActivity”>

<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Quality of Andriod”
android:textSize=”30dp”
android:gravity=”center”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”
app:layout_constraintRight_toRightOf=”parent”
app:layout_constraintTop_toTopOf=”parent” />
<RadioGroup
android:id=”@+id/rating”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:padding=”20dp”>
<RadioButton
android:id=”@+id/rdbexcellent”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”

RadioButton

        android:text=”Excellent”
android:textSize=”30dp”
></RadioButton>
<RadioButton
android:id=”@+id/rdbgood”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”GooD”
android:textSize=”30dp”
></RadioButton>
<RadioButton
android:id=”@+id/rdbBAD”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”BAD”
android:textSize=”30dp”
>

</RadioButton>
</RadioGroup>
</LinearLayout>

 

 

 

 

Radiobutton.java

package com.example.radiobtnonclick;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
RadioGroup Rating;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rating= findViewById(R.id.rating);
Rating.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton=findViewById(checkedId);
switch (radioButton.getId())
{
case R.id.rdbexcellent:
Toast.makeText(MainActivity.this, “Excellent”, Toast.LENGTH_SHORT).show();
break;
case R.id.rdbgood:
Toast.makeText(MainActivity.this, “good”, Toast.LENGTH_SHORT).show();
break;
case R.id.rdbBAD:
Toast.makeText(MainActivity.this, “bad”, Toast.LENGTH_SHORT).show();
break;
}
}
});
}
}

 

Please follow and like us:

Author: Author

Leave a Reply

Your email address will not be published. Required fields are marked *