我一直在尝试获取这个库: https ://github.com/bauerca/drag-sort-listview/
在 AlertDialog 中工作。但到目前为止我还没有成功。一切看起来都很完美,但拖放不会发生。
有什么建议可以做到吗?如果在 AlertDialog 中没有办法做到这一点,有没有办法在不使用意图的情况下做到这一点?
这是我的代码:
public class FolderSorter
{
Context parent;
ArrayList<String> lists;
ArrayAdapter<String> adapter;
public FolderSorter(Context context)
{
this.parent = context;
lists = new ArrayList<String>();
adapter = new ArrayAdapter<String>(parent, R.layout.list_item1,
R.id.text1);
}
public void setList(List<String> mlist)
{
this.lists.addAll(mlist);
}
public void doSort()
{
LayoutInflater factory = LayoutInflater.from(parent);
final View lview = factory.inflate(R.layout.sort_folders, null);
AlertDialog.Builder builder = new AlertDialog.Builder(parent);
builder.setTitle("Sort Folders");
builder.setView(lview);
// ListView list = (ListView) lview.findViewById(R.id.listView1);
DragSortListView list2 = (DragSortListView) lview
.findViewById(R.id.dragSortListView1);
adapter.addAll(lists);
// list.setAdapter(adapter);
list2.setAdapter(adapter);
// TODO: set buttons OK and CANCEL
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int id)
{
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int id)
{
}
});
final Dialog dialog = builder.create();
dialog.show();
}
private DragSortListView.DropListener onDrop = new DragSortListView.DropListener()
{
@Override
public void drop(int from, int to)
{
String item = adapter.getItem(from);
adapter.remove(item);
adapter.insert(item, to);
}
};
private DragSortListView.RemoveListener onRemove = new DragSortListView.RemoveListener()
{
@Override
public void remove(int which)
{
adapter.remove(adapter.getItem(which));
}
};
}