2016-08-03 52 views
1

Ich entwickle Android-Projekt. In diesem Fall habe ich in einer Aktivität 2 Radioknöpfe eingestellt. Ich will das, wenn ich (1.) den ersten Radiobutton auswähle, wird es zu activity2.wenn ich (Check) den 2. radiobutton auswähle, wird es zu activity3 gehen. Ich will keine Knöpfe. Was ist das Ereignis, das ich benutzen muss. Bitte hilf mir.Verwenden Sie, wenn Bedingung in Radiobutton

Antwort

0

dies wird Ihnen helfen, ...

in 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" 
      /> 

in 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; 
     }