I want to copy the text content in item of a RecyclerView, so I set a OnLongClickListener on the TextView, while it will show a PopupWindow that contain a copy button.
My problem is that while I am still touching the RecycleView when the PopupWindow has shown and scroll the RecycleView, the RecycleView is unexpected to scroll.
I need that if the PopupWindow has shown, no matter I am still touching the RecyclerView or not, the PopupWindow should have the facus, and I can't do others unless the PopupWindow is dismissed.
my init a PopupWindow code:
mPopupWindow = new PopupWindow(context);
mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
View contentView = LayoutInflater.from(context).inflate(R.layout.comment_popup_layout, null);
mPopupWindow.setContentView(contentView);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setTouchable(true);
mPopupWindow.setFocusable(true);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
I use the method showAsDropDown(View anchor, int xoff, int yoff)
to show the window.
Need some help, after I have seached google for a long time.
Thanks!
Pass the object of RecyclerView in constructor of adapter class and initialize it then add this in constructor
if(mPopupWindow.isShowing()){
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
}