2016-08-03 3 views
1

Я разрабатываю проект для Android. В этом, в одном действии, я установил 2 переключателя. Я хочу, чтобы это было, если я выберу (проверьте) 1-ое радиообъект, он перейдет к активности2.если я выберу (проверьте) 2-ое радиообъ ем, он перейдет к активности3. Я не хочу никаких кнопок. Какое событие я должен использовать. Пожалуйста помогите.Использование, если условие в radiobutton

ответ

0

это поможет ...

в XML

<RadioGroup 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="left" 
     android:layout_margin="25dp" 
     android:background="#FF0" 
     android:paddingRight="50dp" 
     > 

     <RadioButton 
      android:id="@+id/Radio_Windows_Phone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Windows Phone 7 Silverlight Cookbook" 
      android:onClick="onRadioButtonClicked" 
      /> 
     <RadioButton 
      android:id="@+id/Radio_IOS" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Swift Development with Cocoa" 
      android:onClick="onRadioButtonClicked" 
      /> 

в Java

public void onRadioButtonClicked(View v) 
    { 
     //require to import the RadioButton class 
     RadioButton rb1 = (RadioButton) findViewById(R.id.Radio_one); 
     RadioButton rb2 = (RadioButton) findViewById(R.id.Radio_two); 

     //is the current radio button now checked? 
     boolean checked = ((RadioButton) v).isChecked(); 

     //now check which radio button is selected 
     //android switch statement 
     switch(v.getId()){ 

      case R.id.Radio_one: 
       if(checked) 
        //if first selected 
       break; 

      case R.id.Radio_two: 
       if(checked) 
        //if second selected 

       break; 
     }