티스토리 뷰
RecyclerView (4) - RecyclerView item click 시 context menu 출력하기
parkho79 2021. 2. 17. 09:56이번 포스팅에서는 RecyclerView item click 시 menu 가 나오게 하는 방법 중 context menu 를 이용하는 방법에 대해 알아보자.
참고로, 지난 포스팅에서는 RecyclerView 에 image + text 출력, click 처리 하는 방법에 대해 알아 보았다.
[Android/UI] - RecyclerView (3) - RecyclerView item 의 click 처리하기
[Android/UI] - RecyclerView (2) - RecyclerView 에 image + text 출력하기
Menu XML resource file 추가
RecyclerView item click 시 나오는 menu 를 XML 로 추가하자.
1. 하단 그림과 같이 res 폴더 안에 'menu' 라는 이름으로 폴더를 추가
2. 'main_list_menu.xml' 를 하단과 같이 생성
3. 1번에서 생성한 menu 폴더에 'main_list_menu.xml' 파일을 추가한다.
RecyclerView item view 에 context menu 등록
새로 생성한 'main_list_menu.xml' 를 RecyclerView item view 에 등록하자.
ListView, GridView 는 'registerForContextMenu' 를 ListView, GridView 에 직접 등록했었다.
RecyclerView 는 'registerForContextMenu' 가 아닌 'setOnCreateContextMenuListener' 를 ViewHolder 에서 등록한다.
1. setOnCreateContextMenuListener : RecyclerView item view 에 context menu 를 등록
2. onCreateContextMenu : Context menu 가 활성화될 때 가장 먼저 호출된다. 이곳에서 menu item 을 생성 하거나 추가할 수 있다.
3. onContextItemSelected : Context menu 가 활성화되고 특정 menu item 을 click 했을 때 호출된다.
Source code
https://github.com/parkho79/RecyclerView_4
'Android > UI' 카테고리의 다른 글
RecyclerView (6) - RecyclerView item 추가, 수정, 삭제 (4) | 2021.02.17 |
---|---|
RecyclerView (5) - RecyclerView item long click 시 popup menu 출력하기 (0) | 2021.02.17 |
RecyclerView (3) - RecyclerView item 의 click 처리하기 (0) | 2021.02.17 |
RecyclerView (2) - RecyclerView 에 image + text 출력하기 (0) | 2021.02.17 |
RecyclerView (1) (0) | 2021.02.17 |
- Total
- Today
- Yesterday
- 리워드앱
- task 생성
- BroadcastReceiver
- 채굴앱
- 앱테크
- android intent
- task
- android task
- 무료채굴
- M2E
- 안드로이드 인텐트
- StringUtils
- p2e
- StartService
- Intent
- RoomDatabase
- onCreateContextMenu
- 앱테크 추천
- registerForContextMenu
- 무료 채굴
- 안드로이드 서비스
- onContextItemSelected
- notifyDataSetChanged
- Android Service
- android flag activity
- 리워드 어플
- bindservice
- WEMIX
- android activity flag
- mPANDO
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |