0% found this document useful (0 votes)
12 views2 pages

Siddik

The document contains an Android application code that implements a user interface with radio buttons and a button to display selected options. It includes a layout with two sets of radio buttons for user selection and a button that triggers a Toast message showing the selected options. The code is structured in Java and utilizes Android's AppCompatActivity for functionality.

Uploaded by

coder2841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Siddik

The document contains an Android application code that implements a user interface with radio buttons and a button to display selected options. It includes a layout with two sets of radio buttons for user selection and a button that triggers a Toast message showing the selected options. The code is structured in Java and utilizes Android's AppCompatActivity for functionality.

Uploaded by

coder2841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import androidx.appcompat.app.

AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RadioButton rb1, rb2, male, female;
String selected;
Button show;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rb1 = (RadioButton) findViewById(R.id.rb1);
rb2 = (RadioButton) findViewById(R.id.rb2);
male = (RadioButton) findViewById(R.id.male);
female = (RadioButton) findViewById(R.id.female);
show = (Button) findViewById(R.id.show);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selected = "";
if (rb1.isChecked()) {
selected = rb1.getText().toString() + "\n";
}
if (rb2.isChecked()) {
selected = selected + rb2.getText().toString() + "\n";
}
if (male.isChecked()) {
selected = selected + male.getText().toString() + "\n";
}
if (female.isChecked()) {
selected = selected + female.getText().toString();
}
Toast.makeText(getApplicationContext(), selected,
Toast.LENGTH_LONG).show();
}
});
}
}

<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:padding="10dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Single Radio Buttons"
android:textColor="#000"
android:textStyle="bold" />
<RadioButton
android:id="@+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 1" />
<RadioButton
android:id="@+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio button inside RadioGroup"
android:textColor="#000"
android:textStyle="bold" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<Button
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:textStyle="bold" />
</LinearLayout>

You might also like