2016-08-27 3 views
0

기본적으로 사용자 로그인으로 활동 로그인에서 라디오 버튼을 선택하고 싶습니다. 활성 버튼 설정은 자동으로 선택되며 사용자가 활동 설정으로 이동 한 다음 라디오 버튼 선택을 변경하면 버튼 선택 사항이 저장됩니다 사용자가 활동을 설정할 때 선택합니다.다른 활동에서 라디오 버튼을 기본 설정으로 선택하는 방법은 무엇입니까?

코드 :

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { 
     // String radiodefault=R.id.Active; 
     @Override 

     public void onCheckedChanged(RadioGroup group, int checkedId) { 

      // find which radio button is selected 

      if(checkedId == R.id.Active) { 

       Toast.makeText(getApplicationContext(), "choice: Active", 

         Toast.LENGTH_SHORT).show(); 
      } 

      else if (checkedId == R.id.Inactive) 
      { 
       Toast.makeText(getApplicationContext(), "choice: Inactive", 

         Toast.LENGTH_SHORT).show(); 

      } 
     } 



    }); 
    active = (RadioButton) findViewById(R.id.Active); 

    inactive = (RadioButton) findViewById(R.id.Inactive); 

    button = (Button)findViewById(R.id.chooseBtn); 

    button.setOnClickListener(new View.OnClickListener() { 



     @Override 

     public void onClick(View v) { 

      int selectedId = radioGroup.getCheckedRadioButtonId(); 



      // find which radioButton is checked by id 

      if(selectedId == active.getId()) { 

       Toast.makeText(Settings.this,"Active is selected",Toast.LENGTH_LONG).show(); 

      } 
      else if(selectedId == inactive.getId()) 
      { 

       Toast.makeText(Settings.this,"Inactive is selected",Toast.LENGTH_LONG).show(); 
+0

shareprefernce를 사용하여 라디오 버튼의 부울 값을 저장하려고합니다. 그리고 SharePrefernce를 사용하여 활동 기록으로 설정하십시오 .... – sushildlh

답변

0

당신은 CheckBox의 값을 저장하고 activity이 재발하면 다시로드 할 SharedPreference를 사용할 수 있습니다. 그런 다음 CheckBox 등의 현재 상태를 설정할 수 있습니다

boolean isActive = preferences.getBoolean("Active",false); 
boolean isInActvie = preferences.getBoolean("InActive",false); 

:

SharedPreferences preferences = getSharedPreferences("checkBox",MODE_PRIVATE); 
     SharedPreferences.Editor editor = preferences.edit(); 
     editor.putBoolean("Active",active.isChecked()); 
     editor.putBoolean("InActive",inactive.isChecked()); 
     editor.apply(); 

그리고 활동을로드로 검색

active.setChecked(isActive); 
inactive.setChecked(isInActive); 
0

사용 SharedPreference를 기본으로 선택 저장하려면 값

관련 문제