[英]Android, simply view question about view reset
I have a button in my activity, when you click the button an if statement is ran against its text label; 我的活动中有一个按钮,当您单击该按钮时,if语句将针对其文本标签运行;
if(BTN_1.getText()=="firsttext"){
//do some stuff, then...
BTN_1.setText("secondtext");
}else if(BTN_1.getText()=="secondtext"){
//do other stuff, then...
BTN_1.setText("firsttext");
}
Firstly, if I hit the home button and go back to the desktop and then click back onto my app the view has reset its self; 首先,如果我按下主页按钮,然后回到桌面,然后再单击回到我的应用程序,则视图已重置其自身。 if I press the button and leave it in a state where the text of the button is "secondtext", when I return to my app it says "firsttext", how can I stop the view of my app refreshing its self like this?
如果按下按钮并将其保持在按钮的文本为“第二文本”的状态,当我返回到我的应用程序时,它显示为“第一文本”,如何停止应用程序的视图以刷新自身状态?
Secondly, under my XML layout I have defined the buttons text; 其次,在我的XML布局下,我定义了按钮文本; android:text="firsttext" But this won't actually match my if statement above, under onCreate of this app I have: BTN_CONNECT.setText("Connect");
android:text =“ firsttext”但这实际上与上面的if语句不匹配,在此应用程序的onCreate下,我具有:BTN_CONNECT.setText(“ Connect”); But visually the text of the button is exactly the same, why won't it match?
但是在视觉上按钮的文本完全相同,为什么不匹配?
Thanks for reading :) 谢谢阅读 :)
Where do I start? 我从哪里开始?
equals()
, not ==
. equals()
而不是==
。 Activity.saveInstanceState()
(so it will persist if you change orientation), or in the SharedPreferences
if you want it to persist forever. Activity.saveInstanceState()
(这样,如果您更改方向,它将保持不变),或者如果您希望状态一直保持不变,则可以在SharedPreferences
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.