Radiogroup Usage example of Android programming development _android

Source: Internet
Author: User
Tags gettext

This example describes the Radiogroup usage of Android programming. Share to everyone for your reference, specific as follows:

Radiogroup is sometimes more useful. The main feature is to provide users with a more selective mechanism.

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;
  @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
  Setcontentview (R.layout.activity_main);
  Group_temo = (radiogroup) Findviewbyid (r.id.radiogroup1);
  Change the default option Group_temo.check (R.ID.RADIO1);
  Gets the default 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 ();  Registering event Group_temo. Setoncheckedchangelistener (New Radiogroup.oncheckedchangelistener () {@Override public void OnCheckedChanged (radiogroup group, int checkedid) {//Click event to get 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: paddingbottom= "@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" Androi d:layout_height= "Wrap_content" android:checked= "true" android:text= "@string/text_java"/> <radiobutton an Droid:id= "@+id/radio1" android:layout_width= "Wrap_content" Android: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>

I hope this article will help you with your Android programming.

Related Article

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.