I have two activity, namely A and B, A is the main interface, there edittext and button above, there listview B above (listview above, I put a switch control), I pressed the button to jump from A to B, B to set listview's switch to true or false, when set up, I press the return key to return to B A, then I'll jump through A, B button, I found I just switch settings are restored, I set no state, how to be able to make B returns A still save the state after the set before me? Seek guidance! ! !<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
A return to the time, the B variable is stored in the Preferences inside, and then start the next time B read this variable to restore it.
Reply:
With over sharedPerferenced to save, and then when you want to use and then taken out
Reply:
It says on the most suitable SharedPerferenced it.
Reply:
Thanks for your answer, but now there is a problem,
Listview in B interface has three rows, each row of data has textview and switch controls,
I onResume in the state into CHECK_STA switch array,
protected void onResume () {
/ / TODO Auto-generated method stub
super.onResume ();
CHECK_STA [0] = sp.getBoolean (SWITCH_1_KEY, true);
CHECK_STA [1] = sp.getBoolean (SWITCH_2_KEY, true);
CHECK_STA [2] = sp.getBoolean (SWITCH_3_KEY, true);
/ / Sp is SharedPreferences sp;
/ / List is (ListView) findViewById (R.id.listView1);
for (int i = 0; i <3; i + +)
{
View view = (View) list.getChildAt (i);
Switch mSwitch = (Switch) view.findViewById (R.id.switch1);
mSwitch.setChecked (CHECK_STA [i]);
}
} But in any case the value of view are null! ! ! How can I get the value of the listview switch it? ? ? ! ? ! ? ?
Reply:
OnPause when you go up the value stored .....
I guess when onResume listview not load up, so to get the view is null
Reply:
Blessings, so it should be is wrong, thank you for your answer, I had the idea a bit wrong, you can now have saved interface above set! ! Results posted slightly, for everybody ~ ~
No comments:
Post a Comment