اون مشکلی که در بالا گفتم خود تو پروژه شما که از arrayadapter اکستندز شده با کدی که در بالا گذاشتید برطرف میشه.
ولی تو کلاسی که از CursorAdapter گرفته شده اینطور نیست .. منم هر کاریش کردم نتونستم اینو درست کنم
کد کلاس را در زیر قرار میدم
فکر کنم باید me را مانند likes[position] مساوی yes یا no قرار بدم که باز هم نمیشه
public class MyAdapter extends CursorAdapter {
Context b;
LayoutInflater inflater;
@SuppressWarnings("deprecation")
public MyAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
b= (Context) context;
}
@SuppressWarnings("unused")
@Override
public void bindView(View view, Context context, final Cursor cursor) {
// TODO Auto-generated method stub
TextView tv1 = (TextView)view.findViewById(R.id.txt_name);
TextView tv2 = (TextView)view.findViewById(R.id.txt_numer);
tv1.setText(cursor.getString(2));
tv2.setText(cursor.getString(3));
final int pos = cursor.getPosition();
final Button favorite_check= (Button)view.findViewById(R.id.favorite_check);
final CheckBox repeatChkBx = (CheckBox)view.findViewById(R.id.favorite_check);
String me = cursor.getString(cursor.getColumnIndex("like"));
if (me.equals("yes")) {
repeatChkBx.setChecked(true);
} else {
repeatChkBx.setChecked(false);
}
repeatChkBx.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
MyDatabase MyDatabase = new MyDatabase(b);
SQLiteDatabase mydb = MyDatabase.getWritableDatabase();
cursor.moveToPosition(pos);
if (repeatChkBx.isChecked()) {
mydb.execSQL("update list set like = 'yes' where id = " + cursor.getString(1));
}else{
mydb.execSQL("update list set like = 'no' where id = " + cursor.getString(1));
}
}
});
}
protected Context getActivity() {
// TODO Auto-generated method stub
return null;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.item, parent, false);
}
}