2015-03-25 5 views
1

меня RadioGroup называется statusGroup, которые содержат две кнопки радио, первый один называется statusDone другие называются statusNotDoneандроида - как переинициализировать мой переключатель по умолчанию

я сделать кнопку по умолчанию проверки радио statusNotDone в моем xml-файле android:checked="true", у меня есть кнопка сброса, мне нужно повторно инициализировать мою переменную переключателя по умолчанию.

<?xml version="1.0" encoding="utf-8"?> 
     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

     <RadioGroup 
      android:id="@+id/statusGroup" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@id/status" 
      android:orientation="horizontal" 
      android:layout_marginTop="12dp" > 

      <RadioButton 
       android:id="@+id/statusDone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/done_string" /> 

      <RadioButton 
       android:id="@+id/statusNotDone" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:checked="true" 
       android:text="@string/not_done_string" /> 
     </RadioGroup> 

    </RelativeLayout> 

мой ява файл

 @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.add_todo); 

    mDefaultStatusButton = (RadioButton) findViewById(R.id.statusNotDone); 
      mDefaultPriorityButton = (RadioButton) findViewById(R.id.medPriority); 
      mPriorityRadioGroup = (RadioGroup) findViewById(R.id.priorityGroup); 
      mStatusRadioGroup = (RadioGroup) findViewById(R.id.statusGroup); 

    } 


    // TODO - Set up OnClickListener for the Reset Button 
      final Button resetButton = (Button) findViewById(R.id.resetButton); 
      resetButton.setOnClickListener(new OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        Log.i(TAG, "Entered resetButton.OnClickListener.onClick()"); 

        // TODO - Reset data to default values 
        mTitleText.setText(""); 

        // how to reinitialize to the default radio buttons 

        // reset date and time 
        setDefaultDateTime(); 
       } 
      }); 

ответ

3
// Please clear radio group using clearCheck() function 
    // Check default radio button using check() function 

    statusGroup.clearCheck(); 
    statusGroup.check(R.id.statusNotDone); 
Смежные вопросы