如何在Android的recyclerview中进行多重选择?

时间:2019-03-20 02:44:38

标签: java android android-recyclerview recycler-adapter

我正在使用recyclerview。我想将多选添加到我的列表中。第一次点击应该是在该正常点击之后的长时间点击。长按可以正常工作,但单击不起作用。单击功能起作用,但是所选列表未添加到列表中。需要帮忙。提前致谢。 下面的代码用于长按

 clickSupport.setOnItemLongClickListener((recyclerView, position, v) -> {
        Log.e("CLF","longClick");//M
        selectedCallLogs = new ArrayList<>();
        selectedCallLogsSocketId= new ArrayList<>();
        selectedCallLogs.add(callLogsList.get(position));
        callLogsAdapter.setSelectedLogs(selectedCallLogs);
        refreshAdapter();
        if(!selectedCallLogs.isEmpty())
        callLogDeleteListener.onCallLogSelected(selectedCallLogs, selectedCallLogs.size());
        return true;
    });
    setCallLogsInfo();

下面的代码用于短按

clickSupport.setOnItemClickListener((recyclerView, i, view1) -> {
       if (selectedCallLogs.isEmpty()){

       }
       else{
           CallLogs selectedLogss = callLogsList.get(i);
           if (selectedCallLogs.contains(selectedLogss)){
               selectedCallLogs.remove(selectedLogss);
           }
           else{
               selectedCallLogs.add(selectedLogss);
           }
           callLogDeleteListener.onCallLogSelected(selectedCallLogs,selectedCallLogs.size());
           callLogsAdapter.setSelectedLogs(selectedCallLogs);
           refreshAdapter();
       }

在“多项选择”之后,我要删除这些列表。

0 个答案:

没有答案