我已經實現了一個應用程序來保存android內容視圖的屬性。如何保存android控件的屬性?
我已經使用複選框啓用和禁用editText.When用戶檢查複選框,然後我啓用編輯文本視圖,當用戶取消選中複選框,然後禁用編輯text.Here如果用戶選中複選框然後編輯文本視圖將啓用輸入數據,然後用戶點擊保存按鈕,然後在編輯欄propertie爲實現將保存,如果用戶重新午餐應用
我已經爲它實現的代碼如下:
((EditText)findViewById(R.id.editText1)).setEnabled(false);
((CheckBox)findViewById(R.id.checkBox1)).setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
((EditText)findViewById(R.id.editText1)).setEnabled(true);
}
else{
((EditText)findViewById(R.id.editText1)).setEnabled(false);
}
}
});
((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//here how to save the properties of editText1 and checkBox1 upto re-launch
}
});
如果用戶重新打開應用程序,則只會顯示修改後的內容。
請任何機構幫助我....
感謝您的答案,但我可以實現在按鈕的事件上面的代碼? – 2012-03-21 09:44:35
這些方法(onSaveInstanceState,onRestoreInstanceState)將在您的活動被創建之前以及在它被殺死之前被調用。所以實際上你不必在按鈕事件中實現這個功能。如果您想在按下按鈕時保存信息,則可以使用sharedPreferences。你可以在我的回答中找到一個鏈接,上面的 – 2012-03-21 10:00:09
添加一些編輯。 – 2012-03-21 10:01:24