제가 커서 아답터를 상속받아서 새로 만들었거든요
그래서 리스트 뷰 항목으로 텍스트 뷰와 체크박스를 넣었구요 그리고
체크 박스 선택하고 삭제하면 디비에서 체크한 항목을 조사해서 삭제하고 다시뿌려주는건데
checkList 가 ArrayList입니다 setTag를 이용해서 체크된키값을 이용해서 디비 삭제하게했거든요
디비는 삭제가 잘돼는데 adapter.getCursor().requery(); 이부분만 타면 invalid statement in fillwindow() 오류나면서
리스트항목들이 싹사라집니다 ㅠㅠ
if((checkList != null)){
StringBuffer sql = new StringBuffer();
String where=" or eng_word ='";
String or ="' or eng_word='";
if(checkList.size() != 0){
for(int i=0; i<checkList.size(); i++){
if(i == 0){
where =" eng_word ='";
}
if(checkList.size() ==1){
where+=checkList.get(i).toString()+"';";
}else{
if(i ==(checkList.size() -1)){
or ="';";
}
where+=checkList.get(i).toString()+or;
}
}
//checkList.removeAll(checkList); 초기화
checkList.clear();//이것 역시 초기화
sql.append("\n delete from eng_dic where 1=1 and").append(where);
Log.v(TAG,""+sql.toString());
db = helper.getWritableDatabase();
db.execSQL(sql.toString());
helper.close();
list.clearChoices();//체크박스 선택해제
adapter.getCursor().requery();
}else{
Toast.makeText(getApplicationContext(),"삭제할 단어를 체크해주세요",Toast.LENGTH_SHORT).show();
}
}
public class CustomAdapter extends CursorAdapter {
String [] from;
int[] to;
public CustomAdapter(Context cntx,Cursor cursor,String[] from,int[] to)
{
super(cntx, cursor,true);
this.from=from;
this.to=to;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final TextView textview =(TextView)view.findViewById(to[0]);
CheckBox chk =(CheckBox)view.findViewById(R.id.chk);
textview.setText(cursor.getString(1));
chk.setOnClickListener(new CheckBox.OnClickListener(){
public void onClick(View v){
if(checkList == null){
checkList = new ArrayList<String>();
}
switch(v.getId()){
case R.id.chk:
CheckBox chk = (CheckBox)v;
chk.setTag(textview.getText());
if(chk.isChecked()){
chk.setChecked(true);
checkList.add((String)chk.getTag());
//Toast.makeText(main.this,""+(String)chk.getTag(), Toast.LENGTH_SHORT).show();
}else{
chk.setChecked(false);
checkList.remove((String)v.getTag());
}
break;
}
}
});
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.list, parent, false);
return view;
}
}
}