일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 어학·외국어
- 트럼프
- Intent
- 무역전쟁
- 화승엔터프라이즈
- 영어메일
- Java
- 다우
- e-mailwriting
- dataframe
- ruby
- 금리인상
- 토익이메일
- 시황
- 셀트리온
- 안드로이드
- 파이썬
- 사드보복완화
- 나스닥
- LG전자
- 네마녀의날
- 주식시황
- 국제유가
- S&P
- android
- Python
- englishwriting
- 다우산업
- 영어메일쓰기
- toeice-mail
- Today
- Total
Developer MJ Story
[Android/ListView] Android ListView에 두 개의 아이템 표시하기(simple_list_item_2) 본문
[Android/ListView] Android ListView에 두 개의 아이템 표시하기(simple_list_item_2)
집근처 2014. 6. 9. 18:24- ListView의 각각의 List를 설명하는 작은 List를 추가 하고 싶은 경우에 'simple_list_item_2'를 사용
- 'simple_list_item_2'의 사용법은 매우 간단
- Source Code
- Source Code
//변수 선언
ArrayList<HashMap<String,String>> MembersList = new ArrayList<HashMap<String,String>>();
HashMap<String,String> item;
...........
//ListView에 나타낼 String 값 할당
item = new HashMap<String, String>();
item.put("item1", “memberList Name”;
item.put("item2", “member infomation”);
MembersList.add(item);
setListViewText(MembersList);
...........
//위에서 할당한 값을 ListView에 set하고 Display
publicvoid setListViewText(ArrayList<HashMap<String,String>> Members){
SimpleAdapter simpleAdapter = new SimpleAdapter(Main.this, Members, android.R.layout.simple_list_item_2,
new String[] {"item1", "item2"}, newint[] {android.R.id.text1,android.R.id.text2});
ListView list = (ListView)findViewById(R.id.listview);
list.setAdapter(simpleAdapter);
}
- setListViewText라는 함수를 만든 이유는 개발하다 보면 ListView를 한번 display하고 끝나는 것이 아니라 계속해서 그 값을 변경해 할 때가 더 많다. 이렇게 중복해서 사용하는 부분은 따로 함수로 만들어 놓으면 편한것은 물론이고, 나중에 디버깅 하기도 한결 수월함
- Layout에 listview에 대한 설정은 아래와 같이 간하게 추가
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listview" />
- 위의 Source Code를 실행하면 아래와 같은 화면이 실행
'Software > Android' 카테고리의 다른 글
[Android/UDP] UDP socket을 이용한 message send/receive (0) | 2014.06.09 |
---|---|
[Android/AsyncTask] AsyncTask 활용하기 (0) | 2014.06.09 |
[Android/Contacts] 번호를 입력하면 DB저장된 이름을 Return하는 함수 구현 (0) | 2014.06.09 |
[Android/Java] StringTokenizer를 이용한 String 나누기 (0) | 2014.06.09 |
[Android/Intent] Broadcast Receiver(activity와 다른 class)에서 intent로 Activity call하기 (0) | 2014.06.09 |