1package com.cheogram.android;
2
3import android.content.Context;
4import android.util.AttributeSet;
5import android.view.ContextMenu;
6import android.view.View;
7import android.widget.AdapterView.AdapterContextMenuInfo;
8
9public class ContextMenuRecyclerView extends androidx.recyclerview.widget.RecyclerView {
10 protected AdapterContextMenuInfo mAdapterContextMenuInfo = null;
11
12 public ContextMenuRecyclerView(Context context) {
13 super(context);
14 }
15
16 public ContextMenuRecyclerView(Context context, AttributeSet attrs) {
17 super(context, attrs);
18 }
19
20 public ContextMenuRecyclerView(Context context, AttributeSet attrs, int defStyle) {
21 super(context, attrs, defStyle);
22 }
23
24 @Override
25 protected ContextMenu.ContextMenuInfo getContextMenuInfo() {
26 return mAdapterContextMenuInfo;
27 }
28
29 @Override
30 public boolean showContextMenuForChild(View originalView) {
31 mAdapterContextMenuInfo = new AdapterContextMenuInfo(
32 originalView,
33 getChildAdapterPosition(originalView),
34 getChildItemId(originalView)
35 );
36 return super.showContextMenuForChild(originalView);
37 }
38}