[英]Keep the text inside a button for the next run of the application
我有一个按钮,可在单击时更改其中的文本。
<Button android:id="@+id/timelinebtn"
android:text="Button1"
android:background="@android:color/transparent"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="5dp" />
我的应用程序中还有一些其他用户可单击的按钮,根据它们所单击的内容,此按钮内的文本(最初为“ Button1”)会变为带有代码的其他文本:
button1.setText("Changed the text to something other.");
我的问题是,如何保留该按钮在程序的下一次运行中显示的最后一个文本。 再次使其更加清晰-关闭程序时,该按钮如何将文本保存在其中,直到下次运行该应用程序为止。
您将需要将状态保持在某个地方,也许最快的方法是使用共享首选项。
您可以阅读这篇文章 ,它描述了在android中存储数据的所有方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.