我做了這個應用程序,用戶輸入學校名稱,它會鏈接到網站。 所以,我想知道如何保存學校名稱,所以您不必在每次打開應用程序時都將其放入。謝謝。Android如何保存編輯文本的值,即使應用程序終止
我的應用程序包含一個edittext,一個go按鈕(我也想用它來保存)和一個webview。
我做了這個應用程序,用戶輸入學校名稱,它會鏈接到網站。 所以,我想知道如何保存學校名稱,所以您不必在每次打開應用程序時都將其放入。謝謝。Android如何保存編輯文本的值,即使應用程序終止
我的應用程序包含一個edittext,一個go按鈕(我也想用它來保存)和一個webview。
可以使用像這樣保存的值:
final EditText eActNametwo = (EditText)findViewById(R.id.eACTNametwo);
final EditText eActBudtwo = (EditText)findViewById(R.id.eACTBudtwo);
bCreatetwo = (Button)findViewById(R.id.bCreateActivitytwo);
bCreatetwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences settingstwo = getSharedPreferences(actnamefiletwo,0);
SharedPreferences.Editor editortwo = settingstwo.edit();
editortwo.putString("nametwo", eActNametwo.getText().toString());
editortwo.putString("budtwo", eActBudtwo.getText().toString());
editortwo.commit();
}
});
然後ü某處調用值使用此
你需要調用之前您的字符串的onCreate這樣的:
public static final String actnamefiletwo = "actnamebudtwo";
這是我自己的應用程序的例子,希望它有助於
謝謝。它爲我工作。 – NEXTGENINTL
但它有點混亂。你能告訴我你的完整代碼嗎?我無法確定在哪裏將它們放在Web客戶端之間。 – NEXTGENINTL
我建議你在看http://developer.android.com/training/basics/data-storage/index.html 對於這個特殊的點在哪裏,只有一個存儲串,我會用SharedPreference 你會找到你所需要的培訓指導什麼;)
這也不錯。謝謝。 – NEXTGENINTL
使用共享偏好這裏http://stackoverflow.com/questions/ 3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values –
http://developer.android.com/training/basics/data-storage/index.html – 2Dee
使用存儲空間類似sqlite或mysql(在線存儲),Sharedpreference ..我的請求商店sqite或mysql – prakash