6
6
import android .view .View ;
7
7
8
8
public class ItemClickSupport {
9
- /**
10
- * Interface definition for a callback to be invoked when an item in the
11
- * RecyclerView has been clicked.
12
- */
13
- public interface OnItemClickListener {
14
- /**
15
- * Callback method to be invoked when an item in the RecyclerView
16
- * has been clicked.
17
- *
18
- * @param parent The RecyclerView where the click happened.
19
- * @param view The view within the RecyclerView that was clicked
20
- * @param position The position of the view in the adapter.
21
- * @param id The row id of the item that was clicked.
22
- */
23
- void onItemClick (RecyclerView parent , View view , int position , long id );
24
- }
25
-
26
- /**
27
- * Interface definition for a callback to be invoked when an item in the
28
- * RecyclerView has been clicked and held.
29
- */
30
- public interface OnItemLongClickListener {
31
- /**
32
- * Callback method to be invoked when an item in the RecyclerView
33
- * has been clicked and held.
34
- *
35
- * @param parent The RecyclerView where the click happened
36
- * @param view The view within the RecyclerView that was clicked
37
- * @param position The position of the view in the list
38
- * @param id The row id of the item that was clicked
39
- *
40
- * @return true if the callback consumed the long click, false otherwise
41
- */
42
- boolean onItemLongClick (RecyclerView parent , View view , int position , long id );
43
- }
44
-
45
9
private final RecyclerView mRecyclerView ;
46
10
private final TouchListener mTouchListener ;
47
-
48
11
private OnItemClickListener mItemClickListener ;
49
12
private OnItemLongClickListener mItemLongClickListener ;
50
13
@@ -55,30 +18,6 @@ private ItemClickSupport(RecyclerView recyclerView) {
55
18
recyclerView .addOnItemTouchListener (mTouchListener );
56
19
}
57
20
58
- /**
59
- * Register a callback to be invoked when an item in the
60
- * RecyclerView has been clicked.
61
- *
62
- * @param listener The callback that will be invoked.
63
- */
64
- public void setOnItemClickListener (OnItemClickListener listener ) {
65
- mItemClickListener = listener ;
66
- }
67
-
68
- /**
69
- * Register a callback to be invoked when an item in the
70
- * RecyclerView has been clicked and held.
71
- *
72
- * @param listener The callback that will be invoked.
73
- */
74
- public void setOnItemLongClickListener (OnItemLongClickListener listener ) {
75
- if (!mRecyclerView .isLongClickable ()) {
76
- mRecyclerView .setLongClickable (true );
77
- }
78
-
79
- mItemLongClickListener = listener ;
80
- }
81
-
82
21
public static ItemClickSupport addTo (RecyclerView recyclerView ) {
83
22
ItemClickSupport itemClickSupport = from (recyclerView );
84
23
if (itemClickSupport == null ) {
@@ -110,6 +49,65 @@ public static ItemClickSupport from(RecyclerView recyclerView) {
110
49
return (ItemClickSupport ) recyclerView .getTag (R .id .twowayview_item_click_support );
111
50
}
112
51
52
+ /**
53
+ * Register a callback to be invoked when an item in the
54
+ * RecyclerView has been clicked.
55
+ *
56
+ * @param listener The callback that will be invoked.
57
+ */
58
+ public void setOnItemClickListener (OnItemClickListener listener ) {
59
+ mItemClickListener = listener ;
60
+ }
61
+
62
+ /**
63
+ * Register a callback to be invoked when an item in the
64
+ * RecyclerView has been clicked and held.
65
+ *
66
+ * @param listener The callback that will be invoked.
67
+ */
68
+ public void setOnItemLongClickListener (OnItemLongClickListener listener ) {
69
+ if (!mRecyclerView .isLongClickable ()) {
70
+ mRecyclerView .setLongClickable (true );
71
+ }
72
+
73
+ mItemLongClickListener = listener ;
74
+ }
75
+
76
+ /**
77
+ * Interface definition for a callback to be invoked when an item in the
78
+ * RecyclerView has been clicked.
79
+ */
80
+ public interface OnItemClickListener {
81
+ /**
82
+ * Callback method to be invoked when an item in the RecyclerView
83
+ * has been clicked.
84
+ *
85
+ * @param parent The RecyclerView where the click happened.
86
+ * @param view The view within the RecyclerView that was clicked
87
+ * @param position The position of the view in the adapter.
88
+ * @param id The row id of the item that was clicked.
89
+ */
90
+ void onItemClick (RecyclerView parent , View view , int position , long id );
91
+ }
92
+
93
+ /**
94
+ * Interface definition for a callback to be invoked when an item in the
95
+ * RecyclerView has been clicked and held.
96
+ */
97
+ public interface OnItemLongClickListener {
98
+ /**
99
+ * Callback method to be invoked when an item in the RecyclerView
100
+ * has been clicked and held.
101
+ *
102
+ * @param parent The RecyclerView where the click happened
103
+ * @param view The view within the RecyclerView that was clicked
104
+ * @param position The position of the view in the list
105
+ * @param id The row id of the item that was clicked
106
+ * @return true if the callback consumed the long click, false otherwise
107
+ */
108
+ boolean onItemLongClick (RecyclerView parent , View view , int position , long id );
109
+ }
110
+
113
111
private class TouchListener extends ClickItemTouchListener {
114
112
TouchListener (RecyclerView recyclerView ) {
115
113
super (recyclerView );
0 commit comments