문제 도메인을 단순화 할 수 있다고 생각합니다. 기본적으로 나는 버튼을 켜기 위해 환경 설정 활동을 설정했다. 문제는 내가 클릭 한 다음 환경 설정으로 돌아 왔을 때 여전히 부울 스위치를 만들려고했으나 모양이 나 타나는 몇 가지 이유에서 발생했습니다. 코드는 아래에 게시됩니다.토글 버튼이 올바르게 설정되지 않았습니다.
솔루션 나는이 솔루션은 사용자가 토글 버튼을 클릭하고 나는 공공 무효 한 OnCreate 방법에 true로 클릭 가능한 설정 한 이후를 해제 할 때의 문제를 해결하는 것입니다 생각합니다. 사용자가 기본 설정 활동으로 돌아갈 때마다 값은 on으로 설정됩니다. 그 매개 변수를 재정의하는 조건이 내 문제를 해결할 것이라고 생각합니다.
prefs = getSharedPreferences(prefName, 0);
SharedPreferences.Editor editor = prefs.edit();
if (twitter.isChecked() == true)
{
onoffTwitter = true;
editor.putBoolean(TWITTER_KEY, true);
onoffTwitter = true;
}
if (twitter.isChecked() == false)
{
onoffTwitter = false;
editor.putBoolean(TWITTER_KEY, false);
onoffTwitter = false;
}
Toast.makeText(getBaseContext(),
"was the twitter checked" + twitter.isChecked(),
Toast.LENGTH_SHORT).show();
editor.commit();
그리고이 코드는 버튼을 숨기는 다른 활동에서 나온 코드입니다.
SharedPreferences prefs = getSharedPreferences(prefName, 0);
buttonStatus = prefs.getBoolean(TWITTER_KEY, false);
Log.e(LOGS, "What is the value for the twitter feed" + buttonStatus);
Toast.makeText(AndroidGUIActivity.this,
" What is the value for the twitter feed" + buttonStatus,
Toast.LENGTH_SHORT).show();
if (buttonStatus==false) twitter.setVisibility(View.GONE);
나는이 문제를 xml 파일에서 토글 버튼의 초기 값을 설정하여 수정할 수 있다고 생각합니다.