public static final String[] title = new String[] { "배경 1", "배경 2" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ex);
setResult(Activity.RESULT_CANCELED);
rowItem = new ArrayList<ListString>();
for (int i = 0; i < title.length; i++) {
ListString item = new ListString(title[i], false);
rowItem.add(item);
}
listView = (ListView) findViewById(R.id.set);
adapter = new ListViewAdapter(BackgroundActivity.this,
R.layout.ex_name, rowItem);
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(this);
okButton = (Button) findViewById(R.id.ok_button);
cancelButton = (Button) findViewById(R.id.cancel_button);
okButton.setOnClickListener(this);
cancelButton.setOnClickListener(this);
try {
getLoadString();
} catch (Exception e) {
Toast.makeText(this, "get error " + this.save, Toast.LENGTH_SHORT)
.show();
}
}
private void getLoadString() {
SharedPreferences preferences = getSharedPreferences("Background",
Activity.MODE_PRIVATE);
int i = preferences.getInt("title", 0);
boolean b = preferences.getBoolean(String.valueOf(i), true);
this.saveBoolean = b;
this.save = title[i];
}
private void saveDataBoolean(boolean value, int i) {
SharedPreferences preferences = getSharedPreferences("Background",
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("title", i);
editor.putBoolean(String.valueOf(i), value);
editor.commit();
// Toast.makeText(BackgroundActivity.this, key + String.valueOf(value) +
// String.valueOf(i), Toast.LENGTH_LONG).show();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
ListString list = (ListString) parent.getItemAtPosition(position);
if (list.ismCheck() == false) {
list.setmCheck(true);
// Toast.makeText(getApplicationContext(), list.getTitle(),
// Toast.LENGTH_SHORT).show();
} else {
list.setmCheck(false);
}
adapter.notifyDataSetChanged();
this.save = list.getTitle();
this.saveBoolean = list.ismCheck();
this.saveInt = position;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.ok_button:
try {
saveDataBoolean(this.saveBoolean, this.saveInt);
Toast.makeText(this, "저장 되었습니다" + this.save, Toast.LENGTH_SHORT)
.show();
} catch (Exception e) {
Toast.makeText(this, "save error", Toast.LENGTH_LONG).show();
}
finish();
break;
case R.id.cancel_button:
finish();
break;
}
}
}
채크박스와 커스텀 리스트뷰를 이용해서 설정창을 만들고 있습니다. 방금 수정을 하였는데 지금 만들고 있는 것은
백그라운드를 변경 하는 설정 창입니다. 커스텀 리스트 뷰 어뎁터 쪽에 SharedPreferences를 두었다가
그냥 설정 창을 하려는 엑티비티 쪽에 두어서 저장하고 백그라운드가 변경 되는 것은 까지는 되는데...
여전히 체크박스 설정을 어떻게 해주어야 될지 모르겠습니다 ㅜㅜ
그리고 채크박스 하나만 체크 되게 하고 싶습니다 ㅜㅜ 열심히 구글링을 하면서 찾아 보고 있지만....
도저히...어떠한 방법을 하는 것이 좋은지....힌트라도 주신다면 감사하겠습니다 ㅜㅜ