Use of Android Development (--radiogroup)

Source: Internet
Author: User

Radiogroup is sometimes more practical. The main feature is to provide users with a mechanism for multiple selection.

Mainactivity.java

Package Com.example.lesson16_radio;import Android.app.activity;import Android.os.bundle;import Android.widget.radiobutton;import Android.widget.radiogroup;import Android.widget.toast;public class MainActivity Extends Activity {private radiogroup group_temo;private RadioButton Checkradiobutton; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Group_temo = (Radiogroup) Findviewbyid (r.id.radiogroup1);//change default option Group_temo.check (R.ID.RADIO1);//Get Default is selected value Checkradiobutton = (RadioButton) Group_temo.findviewbyid (Group_temo.getcheckedradiobuttonid ()); Toast.maketext (This, "the value of the default option is:" + checkradiobutton.gettext (), Toast.length_long). Show ();//Register Event Group_ Temo.setoncheckedchangelistener (New Radiogroup.oncheckedchangelistener () {@Overridepublic void oncheckedchanged ( Radiogroup Group, int checkedid) {//Click event Gets the Selection object Checkradiobutton = (RadioButton) Group_temo.findviewbyid (Checkedid); Toast.maketext (Getapplicationcontext (),"Get ID is" + checkradiobutton.gettext (), Toast.length_long). Show ();}});}} 


Layout file

<relativelayout 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:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: Context= ".        Mainactivity "> <radiogroup android:id=" @+id/radiogroup1 "android:layout_width=" Wrap_content " android:layout_height= "Wrap_content" android:layout_alignparentleft= "true" android:layout_alignparentright            = "true" android:layout_alignparenttop= "true" > <radiobutton android:id= "@+id/radio0"             Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:checked= "true"  android:text= "@string/text_java"/>      <radiobutton android:id= "@+id/radio1" android:layout_width= "Wrap_content" Androi d:layout_height= "Wrap_content" android:text= "@string/text_net"/> <radiobutton android:            Id= "@+id/radio2" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "@string/text_php"/> </RadioGroup></RelativeLayout>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.