ListView长按删除操作
String[] mItems = {"删除通知", "清除所有通知", "取消"};
//listView长按事件
msg_listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) {
final int position = listData.size() - pos - 1;
final BaseDialog choosedialog = new BaseDialog(activity, BaseDialog.DIALOG_LIST_CHOOSE, ApplicationApp.DIALOG_STYLE, null);
choosedialog.setCancelable(true);
choosedialog.setCanceledOnTouchOutside(true);
choosedialog.setTitleText("选择操作");
choosedialog.setChooseItem(mItems, Gravity.CENTER_VERTICAL, new BaseDialogChooseListener() {
@Override
public void OnItemClick(Dialog dialog, View view, int itemid) {
dialog.dismiss();
if (itemid == 0) {
// 数据库名称为 bjrsMsg
ApplicationApp.bjrsDB.execSQL("delete from bjrsMsg where newsid=" + adapter.getListData().get(position).newsid);
listData.remove(position);
adapter.notifyDataSetChanged();
} else if (itemid == 1) {
ApplicationApp.bjrsDB.execSQL("delete from bjrsMsg");
listData.clear();
adapter.notifyDataSetChanged();
} else if (itemid == 2) {
choosedialog.dismiss();
}
}
});
choosedialog.show();
return false;
}
});