Develop
2013.04.23 16:33
[android] ArrayAdapter를 이용하여 출력하기
조회 수 47347 댓글 0
ArrayAdapter를 이용하여 리스트에 정보 넣기
여러개의 같은형의 다른 정보를 특정 View에 저장하고 보여 주기 위해서 아답터라는 클래스를 사용하여 View와 정보를 연결한다. 그 연결의 기본적인 순서는 아래와 같다.
1. ArrayList를 만든다.
2. ArrayAdapter에 ArrayList를 연결한다.
3. ListView에 아답터를 연결한다.
코드로 풀어보자면
ArrayList<String> aList = new ArrayList<String>();
ArrayAdapter<String> aA = new ArrayAdapter(this, android.R.layout.simple_list_item1, aList);
myListView.setAdapter(aA);
위와 같은 순서가 되겠고.. 이제는 ArrayList에 keyListener를 이용하여 정보를 갱신해 주면 ListVew에 정보가 보이게 된다.
KeyListener의 예)
etxt_my.setOnKeyListener( new OnKeyListener(){ public boolean onKey(View v, int keyCode, KeyEvent event) { if(event.getAction()==KeyEvent.ACTION_DOWN) { if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER) { aList.add(0, etxt_my.getText().toString()); aA.notifyDataSetChanged(); etxt_my.setText(""); return true; } } return false; } });
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
69 | Develop | [c] 기막힌 정렬 코드 ㅋㄷ | hooni | 2015.10.13 | 825 |
68 | Algorithm | OCB5 Injection 앗싸뵹! ㅋㅋ | hooni | 2014.07.01 | 823 |
67 | System/OS | [linux] The Ultimate Wget Download Guide With 15 Awesome Examples | hooni | 2020.05.26 | 822 |
66 | Develop | [io] Apple Watch, Today Extension 앱ID 설정 | hooni | 2016.04.20 | 819 |
65 | Develop | [js] e.stopPropagation() VS e.preventDefault () | hooni | 2015.04.14 | 819 |
64 | System/OS | [macos] How to Fix ‘You Shut Down Your Computer Because of a Problem’ | hooni | 2022.06.01 | 807 |
63 | Develop | [linux] CentOS Apache 웹서버에 HTTPS 적용 | hooni | 2015.10.23 | 798 |
62 | Develop | [Android Error] The number of method references in a .dex file cannot exceed 64K | hooni | 2016.11.10 | 774 |
61 | Develop | [c] 파일명 또는 특정 패턴을 적용 | hooni | 2016.08.03 | 768 |
60 | Develop | 리팩토링 계획안 | hooni | 2017.05.15 | 763 |
59 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 758 |
58 | Develop | [ios][swift] 초간단 TableView 샘플 | hooni | 2016.06.27 | 757 |