
Android RadioButton –“How to select single elements value into the RadioButton in android” from XIC-Coimbatore
Basically radiobutton’s using for the quiz, mcq, gender, etc,. From multiple choices we can select any one element/value.
In your ADT tool create a new Android Application name as RadioButtonExample.
Open activity_main.xml drag and drop the RadioGroup widget from Layouts tab.
Then only we can select any one item from the group.
Then open activity_main.xml page select the radiogroup widget and change the id as rg_ma_gender. And change the value for radiobutton’s as male and female.
Move tab to MainActivity.java page. Create a global object for the RadioGroup as rg, RadioButton rb, Button btn.
Inside the onCreate method use findviewbyid method to connect with the RadioGroup and Button widget xml page to the java page like follow
rg = (RadioGroup) findViewById(R.id.rg_ma_gender);
btn = (Button) findViewById(R.id.btn_click);
Now using click button get value of selected radio item value, so set onClickListener for the Button.
And mention the below code for getting selected item value. Using Toast display the value.
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
int SelectedId=rg.getCheckedRadioButtonId();
rb=(RadioButton)findViewById(SelectedId);
Toast.makeText(MainActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
});
The step are used to single value from multiple radio buttons. User when click the button on that time result will show the value.
Output Screen:
Select Female option and click the button. See the Output below.
For More Android Application Event’s kindly visit our Blog page.
Hope this blog inspires you to embrace change and grow. Whether you are an XPLORER or not, feel free to glance through our blogs and help us guide and support you in your voyage to success. Happy Learning!
- # VLSI
- #A+N+
- #ADO.NET
- #Advanced JAVA
- #ANDROID
- #ARM
- #ASP.NET
- #Big DATA
- #Bootstrap
- #C
- #C Programming
- #CBE
- #CCNA
- #CEH
- #Cloud Computing
- #CodeIgnitor
- #CORPORATE Training
- #CSS
- #DATA MINING
- #Django
- #DNA
- #Embedded systems
- #Ethical Hacking
- #Frameworks
- #Hadoop
- #hibernate
- #HTML5
- #INDIA
- #INSTITUTIONAL Training
- #ITIL
- #J2EE
- #JAVA
- #Java Script
- #LAB View
- #LINUX
- #Magneto
- #MAT LAB
- #MCSA
- #MCSE
- #Mongo DB
- #MVC
- #MySQL
- #Networking
- #OCJP
- #openCV
- #ORACLE
- #PCB Designing
- #Perl
- #PHP
- #PIC
- #Placement Training
- #PLC
- #PLSQL
- #PMP
- #Python
- #R Programming
- #Raspberry Pi
- #RDBMS
- #RETAIL Training
- #RHCE
- #RIA
- #SAP
- #SAS
- #selenium
- #Soft Skills
- #software testing
- #Spring
- #Struts
- #VB.NET
- #Web Designing
- #Windows Server
- #Word press
- #XIC
- #XPLORE IT CORP
0 responses on "Android RadioButton - XIC Coimbatore"