Android,简单查看有关视图重置的问题
我的活动中有一个按钮,当您单击该按钮时,将针对其文本标签运行 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");
}
首先,如果我点击主页按钮并返回桌面,然后单击返回我的应用程序,视图将重置其自身;如果我按下按钮并将其保持在按钮文本为“secondtext”的状态,当我返回到我的应用程序时它显示“firsttext”,我怎样才能停止我的应用程序的视图像这样刷新自己?
其次,在我的 XML 布局下,我定义了按钮文本;安卓:文本=“第一个文本” 但这实际上与我上面的 if 语句不匹配,在这个应用程序的 onCreate 下我有: BTN_CONNECT.setText("Connect"); 但视觉上按钮的文字是一模一样的,为什么会不匹配呢?
感谢您的阅读:)
I have a button in my activity, when you click the button an if statement is ran against its text label;
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; android:text="firsttext"
But this won't actually match my if statement above, under onCreate of this app I have: BTN_CONNECT.setText("Connect");
But visually the text of the button is exactly the same, why won't it match?
Thanks for reading :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从哪里开始?
equals()
来完成,而不是==
。Activity.saveInstanceState()
中执行此操作(这样,如果您更改方向,它就会持续存在),也可以在SharedPreferences
中执行此操作> 如果你想让它永远持续下去。Where do I start?
equals()
, not==
.Activity.saveInstanceState()
(so it will persist if you change orientation), or in theSharedPreferences
if you want it to persist forever.