I think i can simplify the problem domain. Basically i have set the preference activity to have button set to on. The problem arises when i click off and then come back to the preference and its still on i tried to create a boolean switch but form some reason it doesnt work. The code is posted below.
solution
I think the solution is to fix the problem of when the user clicks on the toggle button and turns it off since I have set clickable to true in the public void Oncreate method. Every time the user goes back to the preference activity the value is set to on. I think a condition which overrides that parameter would fix my problem.
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();
And this code is from another activity which hides the button.
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);
I believe I can fix this by setting the initial value of the togglebutton in the xml file.
The problem was I was not passing the preference value to the twitter but so it wasn’t storing the value.