[Link].
3: Develop an application that uses the Radio Button
Aim:
To develop an application that uses the Radio Button
Procedure:
Step 1: Create new project
Step 2: Click xml file (activity_main.xml)
Step 3: Click design option and design your application using (RadioGroup, RadioButtons
and 1 Button)
Step 4: Now, open up the activity java file ([Link]).
Step 5: Write the code for radio button selection.
Step 6: Add the click listener to the Display button.
Step 7: When that button has been clicked, selected radio button text will be displayed in the
Toast.
Step 8: End.
Code:
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
RadioButton radioButton1, radioButton2, radioButton3, radioButton4;
String selectedSubject;
Button submit;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
radioButton1 = (RadioButton) findViewById([Link].radioButton1);
radioButton2 = (RadioButton) findViewById([Link].radioButton2);
radioButton3 = (RadioButton) findViewById([Link].radioButton3);
radioButton4 = (RadioButton) findViewById([Link].radioButton4);
submit = (Button) findViewById([Link].button3);
[Link](new [Link]() {
@Override
public void onClick(View v) {
if ([Link]()) {
selectedSubject = [Link]().toString();
} else if ([Link]()) {
selectedSubject = [Link]().toString();
} else if ([Link]()) {
selectedSubject = [Link]().toString();
} else if ([Link]()) {
selectedSubject = [Link]().toString();
}
[Link](getApplicationContext(), selectedSubject,
Toast.LENGTH_LONG).show();
}
});
}
}
Output:
Result:
This Mobile Application has been created and tested successfully.