【问题标题】:toast after removing last item from recyclerview android从recyclerview android中删除最后一项后吐司
【发布时间】:2016-10-22 15:32:01
【问题描述】:

我有一个带有适配器的 recyclerview。我在 onbindviewholder 中使用以下方法从列表中删除项目。

List<MyList> myList;
Adpater myAdapter = myList.get(position);
myList.remove(position);
notifyDataSetChanged();

从列表中删除最后一项后,我想敬酒。请帮忙。

【问题讨论】:

  • 只检查适配器中列表的长度如果为 0 然后显示 toast
  • 如何设置条件?有参考吗?
  • 你可以在myList.remove(position);之后设置toast。
  • 你能做到if ( myList.size() == 0 ) showToast(); else myList.remove(position);
  • @Akash 成功了

标签: android android-recyclerview notifydatasetchanged


【解决方案1】:

myList.remove(position); 行之后设置toast

【讨论】:

    【解决方案2】:

    我看到它是自定义适配器,所以你可以重写方法来检查空:

    @Override
    public boolean isEmpty() {
    
        return items.size()==0; //items is example collection
    
    }
    

    使用那个方法

    if (myAdapter.isEmpty()){
      //here toast show
    }
    

    【讨论】:

    • 这通常在列表大小为 0 时有效。删除项目后如何检查列表大小??
    • 知道了。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2018-02-23
    相关资源
    最近更新 更多