
我试图添加滑动功能以删除以及在长按RecyclerVIEw项目时显示底部工作表d出窗口.我正在使用itemtouchhelper.SimpleCallback进行滑动删除,并使用ItemtouchListener进行长按显示d出窗口.
问题是,当我轻扫项目以删除它时,还会检测到长按.
我要的是在滑动项目时应忽略长按.
我有itemtouchhelper类,该类扩展了Simplecallback以便将其删除.以下是附加recyclervIEw以便删除的代码.
itemtouchhelper.SimpleCallback itemtouchhelperCallback = new Recycleritemtouchhelper(0, itemtouchhelper.left, this); new itemtouchhelper(itemtouchhelperCallback).attachToRecyclerVIEw(recyclerVIEw);Follwing是为长时间单击事件添加侦听器的代码.
recyclerVIEw.addOnItemtouchListener(new NotesRecyclertouchListener(getApplicationContext(), recyclerVIEw, new NotesRecyclertouchListener.ClickListener() { @OverrIDe public voID onLongClick(VIEw vIEw, int position) { Note note = notesList.get(position); Toast.makeText(getApplicationContext(), note.getTitle() + " is log pressed!", Toast.LENGTH_SHORT).show(); VIEw sheetVIEw = MainActivity.this.getLayoutInflater().inflate(R.layout.vIEw_bottom_sheet_dialog, null); BottomSheetDialog dialog = new BottomSheetDialog(MainActivity.this); dialog.setContentVIEw(sheetVIEw); dialog.show(); } }));解决方法:
正如@DavIDVelasquez所建议的那样,您应在滑动开始时设置一个标志,并根据onLongClick()中的状态进行 *** 作,但onSwiped()并非可行之路.相反,您应该使用itemtouchhelper.SimpleCallback#onChildDraw()方法检测滑动物体的时间,使用onSwiped()方法检测滑动物体的时间.
例如.
overrIDe fun onChildDraw(c: Canvas, recyclerVIEw: RecyclerVIEw, vIEwHolder: RecyclerVIEw.VIEwHolder, dX: float, dY: float, actionState: Int,isCurrentlyActive: Boolean) { if(actionState == itemtouchhelper.ACTION_STATE_SWIPE){ setupMyFlag() }}overrIDe fun onSwiped(vIEwHolder: RecyclerVIEw.VIEwHolder, direction: Int) { clearMyFlag()}然后只需在您的onLongClick()中检查此标志
总结以上是内存溢出为你收集整理的java-如何检测是否正在刷Recyclerview项目?全部内容,希望文章能够帮你解决java-如何检测是否正在刷Recyclerview项目?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)