刷新DragSortListView中的项目

时间:2013-04-29 07:20:37

标签: android listview sorting drag listviewitem

使用DragSortListView创建ListView,因此我可以移动行以重新排序列表。 好吧,我需要修改List的行为。默认情况下,列表无法重新排序(setDragEnabled = false)当用户单击项目菜单时,只有列表才能重新排序(setDragEnabled = true)。 问题是,当我将DragSortListView设置为setDragEnabled为true时,只有当前在屏幕上的项目会受到影响。

例如:如果我的列表有10个项目,但屏幕只能显示6个(因为屏幕大小),那么其他4个项目将受到影响,但不会影响当前屏幕上的6个项目。 不知道这是DragSortListView的“问题”,还是一般来自ListView。

所以我的问题是:如何更新DragSortListView中所有项目的数据?

到目前为止,这就是我所拥有的

switch(item.getItemId()) {
    case R.id.list_menu_item1:              
    ArrayList aL = new ArrayList();
    aL = (ArrayList) findViewWithTagRecursively(dslv,"_indicator");

    for(int i = 0; i < aL.size(); i++){
        dslv.setDragEnabled(true);
        adapter.notifyDataSetChanged();
        ImageView list_image = (ImageView)aL.get(i);
        //aL -> ArrayList with the items (views) in the list.
        list_image.setImageDrawable(this.getResources().getDrawable
               (this.getResources().getIdentifier
                      ("drawable/delete_x",null,this.getPackageName())));
    }
    break;
    default:
    break;
}

1 个答案:

答案 0 :(得分:0)

而不是循环,只需调用

dslv.setDragEnabled(true);
adapter.notifyDataSetChanged();

并在适配器的getView()中根据是否启用拖动来设置drawable。 notifyDataSetChanged()将根据需要为列表项调用getView()