Example of the Android Radiogroup and RadioButton controls simple usage _android

Source: Internet
Author: User
Tags gettext sqlite database

The examples in this article describe the simple use of the Android Radiogroup and RadioButton controls. Share to everyone for your reference, specific as follows:

Radiogroup and RadioButton represent a control of the radio button in Android, and write a simple code that is familiar:

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.RadioButton;
Import Android.widget.RadioGroup;
Import Android.widget.RadioGroup.OnCheckedChangeListener;
Import Android.widget.TextView;
  public class Radio extends activity {private TextView Mytextview;
  Private RadioButton chinabtn;
  Private RadioButton ukbtn;
  Private RadioButton usabtn;
  Private Radiogroup RG; /** called the activity is a.
    * * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Setcontentview (R.layout.main);
    Find TextView Mytextview = (TextView) Findviewbyid (r.id.mytextview) by ID;
    Find RadioButton chinabtn = (RadioButton) Findviewbyid (R.id.china_button) by ID;
    UKBTN = (RadioButton) Findviewbyid (R.id.uk_button);
    USABTN = (RadioButton) Findviewbyid (R.id.usa_button);
    Find Radiogroup RG = (radiogroup) Findviewbyid (r.id.rbtngroup) by ID; Just listen to the Radiogroup rg.setoncheckedchangelisteNER (new Oncheckedchangelistener () {@Override public void oncheckedchanged (radiogroup group, int checkedid) { TODO auto-generated Method Stub if (R.id.china_button = = Checkedid) {mytextview.settext ("your Chosen country
        Home is: "+ chinabtn.gettext (). toString ());
        else if (R.id.uk_button = = Checkedid) {Mytextview.settext ("The country you selected is:" + ukbtn.gettext (). toString ()); else if (R.id.usa_button = = Checkedid) {Mytextview.settext ("The country you selected is:" + usabtn.gettext (). toString
        ());
  }
      }
    });

 }
}

The

Main.xml file is as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" "Fill_parent"
  ; <textview android:id= "@+id/mytextview" android:layout_width= wrap_content "android:layout_height=" Wrap_cont Ent "android:text=" @string/hello "/> <radiogroup android:id=" @+id/rbtngroup "Android:layout_width=" W Rap_content "android:layout_height=" wrap_content "> <radiobutton android:id=" @+id/china_bu Tton "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" "China"/&G
    T <radiobutton android:id= "@+id/uk_button" android:layout_width= "Wrap_content" W Rap_content "android:text=", "British"/> <radiobutton android:id= "@+id/usa_button" android:layout
_width= "Wrap_content"      android:layout_height= "Wrap_content" android:text= "USA"/> </RadioGroup> </LinearLayout>

The effect is as follows:

More interested readers of Android-related content can view the site: "Summary of the usage of Android controls", "Summary of operational techniques for Android Programming", "Android View tips Summary", " Android Operation SQLite Database skills Summary, "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android File Operation skills Summary", "Android programming development of SD card operation method Summary", " Android Resource Operation tips Summary and Android development introductory and advanced tutorials

I hope this article will help you with the Android program.

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.