2010-11-19 5 views
-2

새로운 Android 버전입니다. 내 요구 사항은 하나의 라디오 버튼을 선택하고 Android에서 해당 활동으로 이동하는 것입니다. 아무도 도와 줄 수 있습니까? 당신이 필요한 모든 사람들이 가이드에 설명되어하나의 라디오 버튼을 선택하고 해당 활동을 Android에서 수행하는 방법은 무엇입니까?

+0

적어도 뭔가하려고 했습니까? 제 말은 ... 이미 프로그래밍 된 체크 박스가 있습니까? 그렇다면 우리가 도울 수있는 코드를 제공해 주시겠습니까? – Cristian

답변

1

다음은이의 예입니다 당신. 위의보기로 된 setContentView 후 라디오 버튼을 찾아 설치 청취자를 점검 활동을위한에서 onCreate에서

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

이는 XML이 그룹화 된 라디오 버튼 레이아웃입니다.

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)); 
      } 
     } 
    }); 
} 
관련 문제