开发者

Setting spinners onResume doesn't work

I want to save text from 2 edittexts(et1,et2) and selection from 3 spinners(spinnerm,spinner and spinner2) onPause and settin开发者_如何学JAVAg 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?


you need to invalidate the view after calling setSelection / setText.

you can invalidate the entire view with mYourView.invalidate(); or you can invalidate just part of a view or a particular drawable. See the View class documentation.

If you want the spinner animation to run as the spinner gets to the value on resume, use the form of setSelection that has a second boolean parameter and pass true in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜