【问题标题】:Refresh items in DragSortListView刷新 DragSortListView 中的项目
【发布时间】:2013-04-22 19:08:22
【问题描述】:

我正在使用 DragSortListView 创建一个 ListView,因此我可以移动行以重新排序列表。 好吧,我需要修改列表的行为。默认情况下,列表不能重新排序(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;
}

【问题讨论】:

    标签: android listview sorting drag listviewitem


    【解决方案1】:

    不用循环,直接调用

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

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

    【讨论】:

      猜你喜欢
      • 2013-06-24
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 2017-06-02
      • 2018-07-12
      • 2012-09-21
      • 2011-07-03
      • 2011-02-19
      相关资源
      最近更新 更多