Create Radio buttons with Radio Group in Android(Part-1)
Hi.Recently i am developed a mobile application for Android device.For this application i am created so many static and dynamic controls like Radio
buttons,Editbox's and some other.In this post(Part-1) , i would like share the procedure of creating a Static controls in Android.In the part -2, i am going to explain the about dynamic controls..so lets start for part-1
First Create one xml file and change the name as static_radiobuttons.xml
Next,create one linear layout and Radio group with two Radio buttons..for this add the following code
Next,Save the xml file Next,Create one class file and one method in that file ,like this
private void AddActionsDescription()
{
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View actionView = li.inflate(R.layout.static_radiobuttons, null);
//Retreive the radio buttons using id's
final RadioGroup radiogroup = (RadioGroup) actionView.findViewById(R.id.group1);
final RadioButton radio_yes = (RadioButton) actionView.findViewById(R.id.radio_Yes);
final RadioButton radio_no = (RadioButton) actionView.findViewById(R.id.radio_No);
//Adding an action for performing while user click on radio button
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup rg, int checkedId)
{
for(int i=0;i < rg.getchildcount();i++)
{
if(radio_yes.getId() == checkedId)
{
Log.v("Ur selected","Yes");
return;
}
elseif(radio_no.getId() == checkedId)
{
Log.v("Ur selected","No");
return;
}
}
}
}
}
That's..it ..My friends..if you have any doubts please free to kept a commnets...Happy CodingSayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.
Labels: Android, Android Controls, Android Tutorials, AndroidBasic, Sqlite, Tanisha
2 Comments:
Thanks for sharing.......
Nice Explanation.....
Post a Comment
Subscribe to Post Comments [Atom]
<< Home