RxView防抖,解决多次点击问题,多次点击只产生一次请求,防抖动
1 RxView.clicks(cb_all).throttleFirst(2000, TimeUnit.MICROSECONDS).subscribe(aVoid -> { 2 if (cb_all.isChecked()) { 3 mSelectedTicketDownInfoBeans.clear(); 4 if (mTicketDownInfoBeans.size() > 0){ 5 mSelectedTicketDownInfoBeans.addAll(mTicketDownInfoBeans); 6 }else { 7 mSelectedTicketDownInfoBeans.addAll(allTypeTickets); 8 } 9 } else { 10 mSelectedTicketDownInfoBeans.clear(); 11 //allTypeTickets存储到数据库的表中 12 13 } 14 15 tv_selected.setText("已选" + mSelectedTicketDownInfoBeans.size() + "项"); 16 17 for (TicketDownInfoBean ticketDownInfoBean : mTicketDownInfoBeans) { 18 ticketDownInfoBean.setCheck(cb_all.isChecked()); 19 } 20 mSelectedTicketDownInfoBeans = new ArrayList(new HashSet(mSelectedTicketDownInfoBeans)); 21 mTicketAdapter.setList(mTicketDownInfoBeans); 22 mTicketAdapter.notifyDataSetChanged(); 23 });