我是Android設備編程的新手。我想弄清楚如何將複選框保存在使用simple_list_item_multiple_choice和數組適配器生成的listview中。我希望能夠保存複選框的狀態,以便當用戶點擊後退按鈕轉到另一個清單時,他們可以返回到此清單並在他們離開時拾取。使用陣列適配器保存列表視圖simple_list_item_multiple_choice複選框狀態
請請,請幫助!代碼和/或解釋將是理想的。
代碼:
public class BeachBabyStuff extends Activity {
String[] beachstuffbaby = new String[]{
"Beach Blanket or Mat",
"Beach Towels",
"Beach Umbrella",
"Beach Chair",
"Books/Magazines",
"Radio",
"Pen/Paper",
"Tablet"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
// Getting the reference to the listview object of the layout
ListView listView = (ListView) findViewById(R.id.listview);
// The checkbox for the each item is specified by the layout android.R.layout.simple_list_item_multiple_choice
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, beachstuffbaby);
// Setting adapter to the listview
listView.setAdapter(adapter);
//Manage the onItemClick method
listView.setOnItemClickListener(new OnItemClickListener() {
private View view;
public void onItemClick(AdapterView<?> ListView, View view, int position, long id) {
CheckedTextView textView = (CheckedTextView)view;
textView.setChecked(!textView.isChecked());
this.view = view;
}
});
什麼是當前行爲.. AFAIK各國不應該改變從其他活動返回.. – Ronnie 2012-08-05 11:16:08