如何保存在android系统的结果呢? [英] How to save a result in android?
问题描述
我在机器人编程菜鸟。我有一个小问题。当我点击一个ImageView的,我作出这样的ImageView无形,并设置一个按钮可见。我的问题是你如何保存吗?对于如我点击的ImageView,按钮用来显示和ImageView的消失。我退出程序,然后输入回相同的活动,我想该按钮留在那里。我该如何去这样做?
I'm a rookie in android programming. I have a small problem. When I click a ImageView, I make that ImageView invisible and set a Button to visible. My problem is that how do you save this? For eg, I click the ImageView, Button shows up and ImageView disappears. And I exit the app and enter back into that same activity and I want that Button to remain there. How do I go about doing that?
谢谢!
推荐答案
使用共享preferences
。这里是如何使用它们的一个很好的教程。
Use SharedPreferences
. here is a good tutorial on how to use them. example
但基本上你是好加入这个code到你的活动去
But basically you are good to go by adding this code to your Activity
private boolean isVisible;
@Override
public void onCreate(Bundle myBundle){
super.onCreate(myBundle);
isVisible = getPreferences(MODE_PRIVATE).getBoolean("visible", true);
.... your code
if (isVisible){
// show ImageView
} else {
//don't
}
}
}
public void onPause(){
if(isFinishing()){
getPreferences(MODE_PRIVATE)
.edit().
putBoolean("visible", isVisible).commit();
}
}
这篇关于如何保存在android系统的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!