我已经实现了CursorAdapter来显示手机通讯录,它工作正常。现在我想要在点击时实现删除项目。但是项目将只从列表中删除,而不是从电话数据库中删除。删除功能将在CursorAdapter中执行。尝试,但无法做到这一点..帮助我..Android从光标适配器删除列表项目
我的代码是在这里..
ImageButton remFrnd = (ImageButton) view.findViewById(R.id.remove_frnd);
remFrnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Animation fadeOut = AnimationUtils.loadAnimation(context, R.anim.request_animate);
fadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
///////////////////////////////////////////////////////////////////////////
//final int position = listContacts.getPositionForView((View) view.getParent());
// datalist.remove(position);
deleteRecordWithId(itemId);
cursor.requery();
// myAdapter.notifyDataSetChanged();
/////////////////////////////////////////////////////////
notifyDataSetChanged();
}
});
view.startAnimation(fadeOut);
}
}
你可以发布你的'deleteRecordWithId(itemId);'? – Meghna
我正在尝试这个..但是这是数据库..所以他们没有必要.. – Dhiman
den发布您的数据库类too.fisrt得到您的列表选择的项目,从数据库中删除它,并删除整行。 – Meghna