简体   繁体   中英

Keep the text inside a button for the next run of the application

I have a button that changes the text inside in it when clicked.

<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" />

I have some other user clickable buttons in my app, and depending on what they click, the text inside this button (at first "Button1") changes to some other text with the code:

button1.setText("Changed the text to something other.");

My question is how can I keep the last text that the button was showing for the next run of the program. Once again to make it a bit more clear - when I close the program, how the button can save the text inside it until the next run of the application.

You will need to persist the state somewhere, perhaps the fastest way would be using the shared preferences.

You can read this , it describes all ways of storing data in android.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM