안드로이드에서 대량의 데이터 출력 시 어댑터뷰어를 사용한다. 종류는 3가지로 ListView, GridView, Spinner가 있다.

 

ListView는 가장 기본적인 형태로 데이터가 일렬로 나열되는 방식이다.



 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.student.project0512.MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>



GridView는 자바의 GridLayout과 같이 바둑판 무늬처럼 정렬이 되는 방식이다. 일정한 간격으로의 출력이 필요할 때 사용한다.

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.student.project0512.MainActivity">
<GridView
android:id="@+id/gridview"
android:numColumns="auto_fit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>


Spinner는 단어의 의미와 실제 출력되는 화면 상의 차이가 있어 보이는데, 클릭 시 하위 리스트가 출력되는 메뉴바와 같은 결과가 나타난다. 캡처를 하려 했으나 메뉴바 효과를 이해하기에는 부족한 듯 하여 안드로이드 공식 홈페이지의 자료를 가져왔다. 사진과 같이 클릭 시 하위의 메뉴들이 출력되는 형태이다. 




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.student.project0512.MainActivity">
<Spinner
android:id="@+id/sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>


세 가지 방식을 모두 예제에 적용을 해봤는데, 어떤 방식을 사용하든 유지보수 측면에서도 매우 편리한 기능이다

+ Recent posts