设置旋转器 onResume 不起作用

发布于 2024-08-31 23:43:26 字数 1173 浏览 2 评论 0原文

我想在暂停时保存 2 个编辑文本(et1,et2)中的文本和 3 个微调器(spinnerm、spinner 和 spinner2)中的选择并将它们设置回恢复时。 edittexts 中的文本已正确保存,只有微调器选择无法按预期工作。 我的代码:

  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();

}

我做错了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我要还你自由 2024-09-07 23:43:26

您需要在调用 setSelection / setText 后使视图无效。

您可以使用 mYourView.invalidate() 使整个视图无效;或者您可以仅使视图或特定可绘制对象的一部分无效。 请参阅 View 类文档

如果您希望微调器动画在微调器达到恢复时的值时运行,请使用具有第二个布尔参数的 setSelection 形式并传入 true。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文