티스토리 뷰
이번 포스팅부터는 모발일 UI 의 가장 기본적인 정보 표현 widget 인 ListView 에 대해 알아보려 한다.
ListView
public class ListView
extends AbsListView
java.lang.Object | |||||
↳ | android.view.View | ||||
↳ | android.view.ViewGroup | ||||
↳ | android.widget.AdapterView<android.widget.ListAdapter> | ||||
↳ | android.widget.AbsListView | ||||
↳ | android.widget.ListView |
ListView 는 여러 아이템들이 세로 방향으로 나열되는 형태를 말한다.
ListView 는 자체 스크롤을 내장하고 있어 ScrollView 를 포함 할 필요가 없다.
Attributes
◼ id
id 는 해당 ListView 를 유일하게 식별할 수 있는 속성이다.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> |
◼ divider
List item 사이 색상이나 이미지를 지정.
◼ dividerHeight
divider 높이 지정.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:divider="#FF0000" | |
android:dividerHeight="3.00dp" /> |

◼ listSelector
List item 선택 시 그려질 색상이나 이미지를 지정.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:listSelector="#00FF00" /> |

◼ entries
ListView 에 아이템으로 지정할 array 리소스 지정.
해당 속성을 이용하면 java code 없이 리소스 지정만으로도 text 를 출력할 수 있다.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:entries="@array/country_values" /> |
<resources> | |
<string-array name="country_values" translatable="false"> | |
<item>Korea</item> | |
<item>China</item> | |
<item>Japan</item> | |
<item>America</item> | |
<item>NewZealand</item> | |
</string-array> | |
</resources> |

◼ choiceMode
아이템 선택 모드
- singleChoice : 단일 선택
- none : 사용 안 함
- multipleChoice : 다중 선택
- multipleChoiceModal : 커스텀 선택 모드에서 다중 선택
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:choiceMode="singleChoice" /> |
String countryList[] = {"Korea", "China", "Japan", "America", "NewZealand"}; | |
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, countryList); | |
ListView listView = (ListView) findViewById(R.id.listview); | |
listView.setAdapter(arrayAdapter); | |
Colored by Color Scripter |

◼ fastScrollEnabled
빠르게 스크롤 할 수 있는 thumb 사용할지 설정.
◼ fastScrollAlwaysVisible
Fast scroll 을 항상 보이게 할지 설정.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:fastScrollEnabled="true" | |
android:fastScrollAlwaysVisible="true" |
![]() |
![]() |
[fastScrollEnabled:false] | [fastScrollEnabled:true] |
◼ stackFromBottom
아이템을 bottom 부터 쌓을지 설정.
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:stackFromBottom="true" /> |

◼ transcriptMode
아이템이 추가될 때 bottom 으로 자동 스크롤할지 설정.
자동 스크롤 모드
- disabled : 사용 안 함
- normal : 마지막 아이템이 표시된 상태에서 데이터 변경 시 자동 스크롤
- alwaysScroll : 아이템이 표시 여부와 상관없이 무조건 스크롤
<ListView | |
android:id="@+id/listview" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:transcriptMode="normal" /> |
ListView 에 text 출력하기
ListView 에 간단히 text 를 출력하자.
[Android/UI] - ListView (2) - ListView 에 text 출력하기
ListView 에 image 추가하기
ListView 에 text + image 를 출력하자.
[Android/UI] - ListView (3) - ListView 에 image 추가하기
ListView item 의 click 처리하기
ListView item click or long click 시 처리를 추가하자.
[Android/UI] - ListView (4) - ListView item 의 click 처리하기
ListView item click 시 menu 출력하기
ListView item click 시 context menu 를 출력하자.
[Android/UI] - ListView (5) - ListView item click 시 context menu 출력하기
[Android/UI] - ListView (6) - ListView item long click 시 popup menu 출력하기
ListView item 추가, 수정, 삭제
ListView item 을 동적으로 추가, 수정, 삭제하는 방법에 대해 알아보자.
[Android/UI] - ListView (7) - ListView item 추가, 수정, 삭제
ListView 에 header, footer 달기
ListView 에 header, footer 을 추가하는 방법에 대해 알아보자.
[Android/UI] - ListView (8) - ListView 에 header, footer 달기
'Android > UI' 카테고리의 다른 글
ListView (3) - ListView 에 image 추가하기 (0) | 2020.11.19 |
---|---|
ListView (2) - ListView 에 text 출력하기 (0) | 2020.11.05 |
RelativeLayout (0) | 2019.11.06 |
LinearLayout (0) | 2019.11.06 |
FrameLayout (0) | 2019.11.06 |
- Total
- Today
- Yesterday
- notifyDataSetChanged
- android intent
- 리워드앱
- StartService
- M2E
- onContextItemSelected
- android activity flag
- 리워드 어플
- registerForContextMenu
- android flag activity
- Android Service
- RoomDatabase
- BroadcastReceiver
- mPANDO
- android task
- 채굴앱
- 무료 채굴
- StringUtils
- task
- onCreateContextMenu
- p2e
- 앱테크
- 무료채굴
- WEMIX
- 안드로이드 인텐트
- Intent
- bindservice
- 안드로이드 서비스
- 앱테크 추천
- task 생성
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 |