2010-11-19 4 views
-2

Ich bin neu auf Android, meine Anforderung ist es, einen Radio Button zu wählen und zu dieser entsprechenden Aktivität in Android gehen? Kann mir jemand helfen? Vielen Dank im Voraus .......Wie wähle ich einen Radio Button und gehe zu dieser Aktivität in Android?

+0

Haben Sie zumindest versucht, etwas zu tun? Ich meine ... haben Sie die Checkboxen bereits programmiert? Wenn ja, könnten Sie bitte einen Code angeben, damit wir Ihnen helfen können? – Cristian

Antwort

1

Hier ist ein Beispiel dafür für Sie. Dies ist das XML-Layout mit zwei gruppierten Auswahlknöpfe:

<?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" 
> 

<RadioGroup 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<RadioButton 
android:id="@+id/radiobutton1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="radio 1" 
/> 

<RadioButton 
android:id="@+id/radiobutton2" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="radio 2"/> 
</RadioGroup> </LinearLayout> 

Im onCreate für Ihre Tätigkeit, nachdem Sie auf die obige Ansicht setContentView, finden die Auswahlknöpfe und Setup überprüft Zuhörer.

RadioButton buttonOne = (RadioButton)findViewById(R.id.radiobutton1); 

    buttonOne.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    { 
     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
     { 
      if (isChecked) 
      { 
       //Go to the activity for button 1 here 
       MainActivity.this.startActivity(new Intent(MainActivity.this, ActivityYouWantToGoTo.class)); 
      } 
     } 
    }); 

    RadioButton buttonTwo = (RadioButton)findViewById(R.id.radiobutton2); 

    buttonTwo.setOnCheckedChangeListener(new OnCheckedChangeListener() 
    { 
     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
     { 
      if (isChecked) 
      { 
       //Go to the activity for button 2 here 
       MainActivity.this.startActivity(new Intent(MainActivity.this, ActivityYouWantToGoTo.class)); 
      } 
     } 
    }); 
} 
Verwandte Themen