DragSortListView ( https://github.com/bauerca/drag-sort-listview ) 非常适合拖动排序,我在我的项目中使用它,但我遇到了一个小问题。
我使用带有删除模式的库,每个列表项的右侧都有一个 delete-x 操作,当用户单击该操作时,该项目被删除,但我想添加一个警告对话框供用户确认删除,但不知道该怎么做。!
最佳答案
你必须覆盖删除函数,就像它在 Documentation 中所说的那样
@Override
public void remove(int which) {
Builder builder = new AlertDialog.Builder(context);
builder.setPositiveButton(R.string.your_button_title, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do some custom delete code (e.g delete datamodel)
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// call notifyDataSetChanged() on your adapter otherwise it will be gone!
}
});
builder.setTitle(R.string.your_title);
builder.setMessage(context.getString(R.string.your_message));
builder.show();
}
为了调用此方法,您必须实现RemoveListener,当然您还必须添加监听器:
myDragSortListView.setRemoveListener(this);
希望对您有所帮助!
关于android - DragSortListView 在用户确认后删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584595/