如何在 android studio 中设置和获取性别单选按钮的值?

how to set and get the value of gender radio button in android studio?

大家好,请帮帮我.. 请检查我的代码并添加可能的解决方案..

我有 radiogroup 名称 radioGender 和 radio 按钮名称 radioMale 和 radioFemale。

我的问题是如何将radioMale的值设置为m,radioFemale的值设置为f,然后将值赋值给customers_gender,以便我可以将值保存在数据库中?

registerlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:fillViewport="false">
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent"
        >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView4"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/logo"
            android:maxHeight="54dp"
            android:maxWidth="322dp"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="100dp"
            android:layout_marginRight="100dp" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView5"
            android:layout_below="@+id/imageView4"
            android:layout_centerHorizontal="true"
            android:src="@drawable/lock"
            android:layout_marginLeft="150dp"
            android:layout_marginRight="150dp"
            android:layout_marginTop="-60dp" />

        <RadioGroup
            android:id="@+id/radioGender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageView5"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="-30dp"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/radioMale"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="Mr."
                android:layout_gravity="center_vertical"
                android:textColor="#ff6d6e71" />

            <RadioButton
                android:id="@+id/radioFemale"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:textSize="14dp"
                android:text="Ms."
                android:textColor="#ff6d6e71" />

        </RadioGroup>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtFname"
            android:layout_below="@+id/radioSex"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:hint="First Name"
            android:background="#ffeeeeee"
            android:padding="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#ff6d6e71" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtLname"
            android:layout_below="@+id/txtFname"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:hint="Last Name"
            android:background="#ffeeeeee"
            android:padding="10dp"
            android:textColor="#ff6d6e71"
            android:layout_marginTop="10dp" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txtEmail"
            android:layout_below="@+id/txtLname"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:hint="Email Address"
            android:background="#ffeeeeee"
            android:padding="10dp"
            android:textColor="#ff6d6e71"
            android:layout_marginTop="10dp" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:ems="10"
            android:id="@+id/txtPassword"
            android:layout_below="@+id/txtEmail"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="30dp"
            android:textColor="#ff6d6e71"
            android:background="#ffeeeeee"
            android:padding="10dp"
            android:hint="Password" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:ems="10"
            android:id="@+id/txtPasswordrepeat"
            android:layout_below="@+id/txtPassword"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="30dp"
            android:textColor="#ff6d6e71"
            android:background="#ffeeeeee"
            android:padding="10dp"
            android:hint="Confirm Password" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Sign Up"
            android:id="@+id/btnSignup"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:textColor="#ff6d6e71"
            android:layout_marginTop="10dp"
            android:layout_below="@+id/txtPasswordrepeat"
            android:longClickable="false"
            android:clickable="true"
            android:background="#fffed4d4" />




    </RelativeLayout>
</ScrollView>

RegisterFragment.java

        public class RegisterFragment extends Fragment implements View.OnClickListener{

    public RegisterFragment(){}
    public String customers_gender="m";

    Button btnSignup;
    EditText txtFname, txtLname, txtEmail, txtPassword, txtPasswordrepeat;
    RadioGroup radioGender;

    UserLocalStore userLocalStore;

    String Expn =
            "^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                    +"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?"
                    +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                    +"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?"
                    +"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                    +"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

    Boolean InternetAvailable = false;
    Seocnd detectconnection;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View rootView = inflater.inflate(R.layout.registerlayout, container, false);

        radioGender=(RadioGroup) rootView.findViewById(R.id.radioGender);
        radioGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int childCount = group.getChildCount();
                for (int x = 0; x < childCount; x++) {
                    RadioButton btn = (RadioButton) group.getChildAt(x);


                    if(btn.getId()==R.id.radioMale){
                        btn.setText("m");
                    }else{
                        btn.setText("f");
                    }
                    if (btn.getId() == checkedId) {

                        customers_gender=btn.getText().toString();// here gender will contain M or F.

                    }

                }

                Log.e("Gender", customers_gender);
            }
        });

        txtFname = (EditText) rootView.findViewById(R.id.txtFname);
        txtLname = (EditText) rootView.findViewById(R.id.txtLname);
        txtEmail = (EditText) rootView.findViewById(R.id.txtEmail);
        txtPassword = (EditText) rootView.findViewById(R.id.txtPassword);
        txtPasswordrepeat = (EditText) rootView.findViewById(R.id.txtPasswordrepeat);
        btnSignup = (Button) rootView.findViewById(R.id.btnSignup);
        btnSignup.setOnClickListener(this);

        userLocalStore = new UserLocalStore(getActivity());

        detectconnection = new Seocnd(getActivity());
        InternetAvailable = detectconnection.InternetConnecting();
        if (InternetAvailable) {
        } else {
            NointernetFragment fragment = new NointernetFragment();
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.container, fragment)
                    .commit();
        }

        return rootView;
    }

    @Override
    public void onClick(View v){
        switch(v.getId()){
            case R.id.btnSignup:
                //String customers_gender = txtGender.getText().toString();
                String customers_firstname = txtFname.getText().toString();
                String customers_lastname = txtLname.getText().toString();
                String customers_email_address = txtEmail.getText().toString();
                String customers_password = txtPassword.getText().toString();
                String customers_passwordrepeat = txtPasswordrepeat.getText().toString();

                if(customers_firstname.length()==0){
                    txtFname.setError("First Name is required.");
                }
                else if(customers_lastname.length()==0){
                    txtLname.setError("Last Name is required.");
                }
                else if(customers_email_address.length()==0){
                    txtEmail.setError("Email Address is required.");
                }
                else if(customers_email_address.length()<=4){
                    txtEmail.setError("Email Address must be at least 5 characters long.");
                }
                else if(customers_email_address.matches(Expn)){
                    if(customers_password.length()==0){
                        txtPassword.setError("Password is required.");
                    }
                    else if(customers_password.length()<=6){
                        txtPassword.setError("Your Password must contain a minimum of 7 characters!");
                    }
                    else if(customers_passwordrepeat.length()==0){
                        txtPasswordrepeat.setError("Confirm Password is required.");
                    }
                    else if (!customers_passwordrepeat.equals(customers_password)) {
                        txtPasswordrepeat.setError("The Password Confirmation must match your password!");
                    }else {
                        User user = new User(customers_gender, customers_firstname, customers_lastname, customers_email_address, customers_password);
                        registeredUser(user);
                    }
                }else{
                    txtEmail.setError("Email Address is not valid.");
                }
                break;
        }
    }

    public void registeredUser(User user){
        ServerRequests serverRequests = new ServerRequests(getActivity());
        serverRequests.storeUserDataInBackground(user, new GetUSerCallBack(){
            @Override
            public void done(User returnedUser){
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
                dialogBuilder.setMessage("Your Account Has Been Created!");
                dialogBuilder.setPositiveButton("Ok",null);
                dialogBuilder.show();

                LoginFragment fragment = new LoginFragment();
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.container, fragment)
                        .commit();
            }
        });
    }
}

这里是错误

09-11 18:57:57.409    1023-1023/? D/AndroidRuntime﹕ >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
09-11 18:57:57.409    1023-1023/? D/AndroidRuntime﹕ CheckJNI is ON
09-11 18:57:58.110    1023-1023/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
09-11 18:57:58.119       78-439/? I/ActivityManager﹕ Force stopping package com.example.administrator.mosbeau uid=10040
09-11 18:57:58.130    1023-1023/? D/AndroidRuntime﹕ Shutting down VM
09-11 18:57:58.165    1023-1027/? D/dalvikvm﹕ GC_CONCURRENT freed 95K, 79% free 447K/2048K, paused 1ms+1ms
09-11 18:57:58.165    1023-1033/? I/AndroidRuntime﹕ NOTE: attach of thread 'Binder Thread #3' failed
09-11 18:57:58.609    1036-1036/? D/AndroidRuntime﹕ >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
09-11 18:57:58.609    1036-1036/? D/AndroidRuntime﹕ CheckJNI is ON
09-11 18:57:59.059    1036-1036/? D/AndroidRuntime﹕ Calling main entry com.android.commands.am.Am
09-11 18:57:59.079       78-191/? I/ActivityManager﹕ START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.administrator.mosbeau/.MainActivity} from pid 1036
09-11 18:57:59.089       78-191/? W/WindowManager﹕ Failure taking screenshot for (240x394) to layer 21005
09-11 18:57:59.112    1036-1036/? D/AndroidRuntime﹕ Shutting down VM
09-11 18:57:59.120    1036-1040/? D/dalvikvm﹕ GC_CONCURRENT freed 98K, 77% free 480K/2048K, paused 1ms+1ms
09-11 18:57:59.130    1036-1046/? I/AndroidRuntime﹕ NOTE: attach of thread 'Binder Thread #3' failed
09-11 18:57:59.190    1047-1047/? D/dalvikvm﹕ Not late-enabling CheckJNI (already on)
09-11 18:57:59.220       78-440/? I/ActivityManager﹕ Start proc com.example.administrator.mosbeau for activity com.example.administrator.mosbeau/.MainActivity: pid=1047 uid=10040 gids={3003}
09-11 18:57:59.500        78-93/? W/ProcessStats﹕ Skipping unknown process pid 1034
09-11 18:57:59.500        78-93/? W/ProcessStats﹕ Skipping unknown process pid 1036
09-11 18:57:59.520       78-116/? W/NetworkManagementSocketTagger﹕ setKernelCountSet(10040, 1) failed with errno -2
09-11 18:57:59.909        78-92/? I/Process﹕ Sending signal. PID: 1047 SIG: 3
09-11 18:57:59.909    1047-1052/? I/dalvikvm﹕ threadid=3: reacting to signal 3
09-11 18:57:59.989    1047-1052/? I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
09-11 18:58:00.233        78-81/? D/dalvikvm﹕ GC_CONCURRENT freed 480K, 16% free 15000K/17799K, paused 6ms+18ms
09-11 18:58:00.359    1047-1047/? I/dalvikvm﹕ Could not find method android.view.ViewGroup.onWindowSystemUiVisibilityChanged, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onWindowSystemUiVisibilityChanged
09-11 18:58:00.359    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 13365: Landroid/view/ViewGroup;.onWindowSystemUiVisibilityChanged (I)V
09-11 18:58:00.359    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0008
09-11 18:58:00.409        78-92/? I/Process﹕ Sending signal. PID: 1047 SIG: 3
09-11 18:58:00.409    1047-1052/? I/dalvikvm﹕ threadid=3: reacting to signal 3
09-11 18:58:00.429    1047-1052/? I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
09-11 18:58:00.440    1047-1047/? I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged
09-11 18:58:00.440    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 13361: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
09-11 18:58:00.440    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007
09-11 18:58:00.460    1047-1047/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
09-11 18:58:00.460    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-11 18:58:00.460    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-11 18:58:00.460    1047-1047/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
09-11 18:58:00.460    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 454: Landroid/content/res/TypedArray;.getType (I)I
09-11 18:58:00.460    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-11 18:58:00.600    1047-1049/? D/dalvikvm﹕ GC_CONCURRENT freed 225K, 3% free 12841K/13127K, paused 5ms+4ms
09-11 18:58:00.670    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed 71K, 3% free 12822K/13127K, paused 27ms
09-11 18:58:00.670    1047-1047/? I/dalvikvm-heap﹕ Grow heap (frag case) to 13.302MB for 757776-byte allocation
09-11 18:58:00.750    1047-1049/? D/dalvikvm﹕ GC_CONCURRENT freed 1K, 3% free 13561K/13895K, paused 4ms+3ms
09-11 18:58:00.800    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 3% free 13561K/13895K, paused 24ms
09-11 18:58:00.820    1047-1047/? I/dalvikvm-heap﹕ Grow heap (frag case) to 16.192MB for 3031056-byte allocation
09-11 18:58:00.860    1047-1049/? D/dalvikvm﹕ GC_CONCURRENT freed 0K, 3% free 16521K/16903K, paused 4ms+3ms
09-11 18:58:00.910        78-92/? I/Process﹕ Sending signal. PID: 1047 SIG: 3
09-11 18:58:00.910    1047-1052/? I/dalvikvm﹕ threadid=3: reacting to signal 3
09-11 18:58:00.920    1047-1052/? I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
09-11 18:58:01.020    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed 740K, 7% free 16250K/17415K, paused 28ms
09-11 18:58:01.030    1047-1047/? I/dalvikvm-heap﹕ Grow heap (frag case) to 17.753MB for 1914896-byte allocation
09-11 18:58:01.080    1047-1049/? D/dalvikvm﹕ GC_CONCURRENT freed <1K, 7% free 18120K/19335K, paused 5ms+4ms
09-11 18:58:01.150    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed 467K, 9% free 17654K/19335K, paused 26ms
09-11 18:58:01.160    1047-1047/? I/dalvikvm-heap﹕ Grow heap (frag case) to 18.031MB for 768016-byte allocation
09-11 18:58:01.200    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 9% free 18403K/20103K, paused 29ms
09-11 18:58:01.230    1047-1047/? D/dalvikvm﹕ GC_FOR_ALLOC freed 0K, 9% free 18404K/20103K, paused 30ms
09-11 18:58:01.249    1047-1047/? I/dalvikvm-heap﹕ Grow heap (frag case) to 20.960MB for 3072016-byte allocation
09-11 18:58:01.299    1047-1049/? D/dalvikvm﹕ GC_CONCURRENT freed 0K, 8% free 21404K/23111K, paused 4ms+5ms
09-11 18:58:01.419        78-92/? I/Process﹕ Sending signal. PID: 1047 SIG: 3
09-11 18:58:01.419    1047-1052/? I/dalvikvm﹕ threadid=3: reacting to signal 3
09-11 18:58:01.419    1047-1052/? I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
09-11 18:58:01.479    1047-1047/? W/ActionBarDrawerToggleHoneycomb﹕ Couldn't set home-as-up indicator
09-11 18:58:01.539    1047-1047/? D/gralloc_goldfish﹕ Emulator without GPU emulation detected.
09-11 18:58:01.629       78-106/? I/ActivityManager﹕ Displayed com.example.administrator.mosbeau/.MainActivity: +2s473ms
09-11 18:58:01.670       78-116/? W/NetworkManagementSocketTagger﹕ setKernelCountSet(10021, 0) failed with errno -2
09-11 18:58:07.940    1047-1047/? I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable
09-11 18:58:07.940    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 395: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-11 18:58:07.950    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-11 18:58:07.950    1047-1047/? I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity
09-11 18:58:07.950    1047-1047/? W/dalvikvm﹕ VFY: unable to resolve virtual method 397: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
09-11 18:58:07.950    1047-1047/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-11 18:58:11.519    1047-1047/? E/Gender﹕ f
09-11 18:58:11.519    1047-1047/? D/AndroidRuntime﹕ Shutting down VM
09-11 18:58:11.519    1047-1047/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x409bf1f8)
09-11 18:58:11.539    1047-1047/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalStateException: Could not find a method selectGender(View) in the activity class com.example.administrator.mosbeau.MainActivity for onClick handler on view class android.support.v7.widget.AppCompatRadioButton with id 'radioFemale'
            at android.view.View.onClick(View.java:3031)
            at android.view.View.performClick(View.java:3511)
            at android.widget.CompoundButton.performClick(CompoundButton.java:100)
            at android.view.View$PerformClick.run(View.java:14105)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4424)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoSuchMethodException: selectGender [class android.view.View]
            at java.lang.Class.getConstructorOrMethod(Class.java:460)
            at java.lang.Class.getMethod(Class.java:915)
            at android.view.View.onClick(View.java:3024)
            at android.view.View.performClick(View.java:3511)
            at android.widget.CompoundButton.performClick(CompoundButton.java:100)
            at android.view.View$PerformClick.run(View.java:14105)
            at android.os.Handler.handleCallback(Handler.java:605)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4424)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
09-11 18:58:11.559       78-440/? W/ActivityManager﹕ Force finishing activity com.example.administrator.mosbeau/.MainActivity
09-11 18:58:11.569       78-440/? W/WindowManager﹕ Failure taking screenshot for (240x394) to layer 21010
09-11 18:58:12.081        78-92/? W/ActivityManager﹕ Activity pause timeout for ActivityRecord{419c65b0 com.example.administrator.mosbeau/.MainActivity}
09-11 18:58:12.100        78-92/? I/Process﹕ Sending signal. PID: 1047 SIG: 3
09-11 18:58:12.100    1047-1052/? I/dalvikvm﹕ threadid=3: reacting to signal 3
09-11 18:58:12.120    1047-1052/? I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
09-11 18:58:12.150       78-116/? W/NetworkManagementSocketTagger﹕ setKernelCountSet(10021, 1) failed with errno -2
09-11 18:58:12.829       78-116/? W/NetworkManagementSocketTagger﹕ setKernelCountSet(10040, 0) failed with errno -2
09-11 18:58:14.059    1047-1047/? I/Process﹕ Sending signal. PID: 1047 SIG: 9
09-11 18:58:14.080       78-268/? I/ActivityManager﹕ Process com.example.administrator.mosbeau (pid 1047) has died.
09-11 18:58:14.080        78-89/? I/WindowManager﹕ WIN DEATH: Window{4195e7e0 com.example.administrator.mosbeau/com.example.administrator.mosbeau.MainActivity paused=false}
09-11 18:58:14.119       78-269/? W/InputManagerService﹕ Got RemoteException sending setActive(false) notification to pid 1047 uid 10040

怎么样:

int radioButtonID = radioGender.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);
int idx = radioButtonGroup.indexOfChild(radioButton);

if (idx==0) {
  customers_gender = "m";
} else {
  customers_gender = "f";
}

radioGender 实施 setOnCheckedChangeListener

 radioGender=(RadioGroup)findViewById(R.id.radioGender);

 radioGender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                int childCount = group.getChildCount();
                String gender=null;
                for (int x = 0; x < childCount; x++) {
                    RadioButton btn = (RadioButton) group.getChildAt(x);


                    if(btn.getId()==R.id.radioMale){
                        btn.setText("M");
                    }else{
                        btn.setText("F");
                    }
                    if (btn.getId() == checkedId) {

                         gender=btn.getText().toString();// here gender will contain M or F.

                    }

                }

                Log.e("Gender",gender);
            }
        });