1. 리스트 아이템(String array) 선언
- String[] items = {"one", "two", "three"};
2. 리스트 어뎁터 생성
- ArrayAdapter<String> aa = new ArrayAdapter<String>(this, -view 구조-, items);
- view 구조 -
simple_list_item_1 : line하나에 아이템 하나씩 가지는 listview
simple_list_item_single_choice : line하나에 아이템 하나와 choice가능한 라디오 버튼 하나를 가지는 listview
3. setListAdapter(-어댑터 이름-);
String[] items = {"one", "two", "three"};
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, -simple_list_item_1, items);
setListAdapter(aa);
// 리스트 아이템이 클릭되었을때 인텐트를 생성해 액티비티를 넘어감 (MainActivity -> NextView)
protected void onListItemClick(ListView l, View v, int position, long id) {
// items[position] : 클릭된 아이템(리스트에서의) 인덱스를 위의 아이템 array의 데이터로 넘김
Intent intent = new Intent(MainActivity.this,NextView.class);
intent.putExtra("seleteditem", items[position]); // 추가적인 정보를 넘길때 putExtra() 메소드 사용
startActivity(intent);
}
// xml 파일
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
- android:id="@android:id/list"
다른 엘리먼트의 아이디 들과 다르게, "@android:id/list"를 사용
ListActivity를 상속받아서 접근가능하다던가 뭐라던가ㅏ.....
'Android > ListView' 카테고리의 다른 글
[Android] 리스트뷰 아이템 클릭 이벤트 - ListView Item Click (17) | 2011.07.13 |
---|---|
[Android] 커스텀 리스트뷰 : Custom ListView - Layout : 레이아웃 (37) | 2011.05.04 |
[Android Tip] 커스텀리스트뷰에서 getItemIdAtPosition 관련... (1) | 2011.05.02 |
[Android] ListView - 드래그 시 Background Color가 반전되는 현상 (0) | 2011.03.22 |
[Android] Custom ListView - 커스텀 리스트뷰 (9) | 2010.11.16 |
ListView 만들기 (0) | 2010.09.08 |