티스토리 뷰
하단 그림과 같이 ListView 를 사용하는 많은 앱에서 item click 시 menu 가 나오는 것을 볼 수 있다.
이번 포스팅에서는 ListView item click 시 menu 가 나오게 하는 방법 중 context menu 를 이용하는 방법에 대해 알아보자.
참고로, 지난 포스팅에서는 ListView 에 text + image 목록 출력, click 처리 하는 방법에 대해 알아 보았다.
[Android/UI] - ListView (2) - ListView 에 text 출력하기
[Android/UI] - ListView (3) - ListView 에 image 추가하기
[Android/UI] - ListView (4) - ListView item 의 click 처리하기
Menu XML resource file 추가
ListView item click 시 나오는 menu 를 XML 로 추가하자.
1. 하단 그림과 같이 res 폴더 안에 'menu' 라는 이름으로 폴더를 추가
2. 'main_list_menu.xml' 를 하단과 같이 생성
3. 1번에서 생성한 menu 폴더에 'main_list_menu.xml' 파일을 추가한다.
ListView 에 context menu 등록
새로 생성한 'main_list_menu.xml' 를 ListView 에 등록하자.
1. registerForContextMenu : ListView 에 context menu 를 등록
2. onCreateContextMenu : Context menu 가 활성화될 때 가장 먼저 호출된다. 이곳에서 menu item 을 생성 하거나 추가할 수 있다.
3. onContextItemSelected : Context menu 가 활성화되고 특정 menu item 을 click 했을 때 호출된다.
Source code
https://github.com/parkho79/ListView_4
'Android > UI' 카테고리의 다른 글
ListView (7) - ListView item 추가, 수정, 삭제 (0) | 2020.12.24 |
---|---|
ListView (6) - ListView item long click 시 popup menu 출력하기 (0) | 2020.12.21 |
ListView (4) - ListView item 의 click 처리하기 (0) | 2020.12.04 |
ListView (3) - ListView 에 image 추가하기 (0) | 2020.11.19 |
ListView (2) - ListView 에 text 출력하기 (0) | 2020.11.05 |
- Total
- Today
- Yesterday
- bindservice
- android intent
- android task
- 무료 채굴
- onContextItemSelected
- mPANDO
- notifyDataSetChanged
- 앱테크 추천
- android flag activity
- android activity flag
- onCreateContextMenu
- WEMIX
- p2e
- RoomDatabase
- task 생성
- 리워드 어플
- Intent
- registerForContextMenu
- task
- 앱테크
- BroadcastReceiver
- StartService
- 채굴앱
- 무료채굴
- 안드로이드 서비스
- Android Service
- 안드로이드 인텐트
- M2E
- StringUtils
- 리워드앱
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |