Setting spinners onResume doesn't work

Posted by DixieFlatline on Stack Overflow See other posts from Stack Overflow or by DixieFlatline
Published on 2010-05-08T17:21:13Z Indexed on 2010/05/08 17:28 UTC
Read the original article Hit count: 294

Filed under:
|
|
|

Hello!

I want to save text from 2 edittexts(et1,et2) and selection from 3 spinners(spinnerm,spinner and spinner2) onPause and setting them back onResume. Text from edittexts is saved correctly, only spinner selection don't work as desired. My code:

  public void onResume(){
     super.onResume();
     Log.d("REZUM","notr smo");
     SharedPreferences seti = getSharedPreferences( "pavzica", MODE_PRIVATE);

     spinnerm.setSelection(seti.getInt("m", 0));
         spinner.setSelection(seti.getInt("k", 0));
         spinner2.setSelection(seti.getInt("p", 0));
         et1.setText(seti.getString("zade", ""));
         et2.setText(seti.getString("Vseb", ""));




 }

public void onPause() {
    shraniPolja();
    super.onPause();
}


public void shraniPolja() {
    SharedPreferences seti = getSharedPreferences( "pavzica", MODE_PRIVATE);
    SharedPreferences.Editor edito = seti.edit();

    edito.putString("zade", et1.getText().toString());
    edito.putString("Vseb", et2.getText().toString());
    edito.putInt("m", spinnerm.getSelectedItemPosition());
    edito.putInt("k", spinner.getSelectedItemPosition());
    edito.putInt("p", spinner2.getSelectedItemPosition());
    edito.putBoolean("b", true);
    edito.commit();

}

What am i doing wrong?

© Stack Overflow or respective owner

Related posts about android

Related posts about java