2011-11-07 51 views
0

我有一個按鈕,點擊裏面的時候改變它的文本的下一次運行。保持一個按鈕內部的文本應用

<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."); 

我的問題是,如何保存該按鈕在程序下一次運行時顯示的最後文本。再次 讓它多一點明確的 - 當我關閉程序,如何按鈕可以保存裏面的文字,直到應用程序的下一次運行。

+1

也許你應該閱讀http://developer.android.com/guide/topics/data/data-storage.html#pref – hovanessyan

回答

1

您需要將狀態保持在某個地方,也許最快的方法是使用共享首選項。

您可以閱讀this,它描述了在android中存儲數據的所有方法。