안녕하세요. 안드로이드 공부를 하고 있는 대학생입니다.
요즘 한창 안드로이드 공부에 푹 빠졌는데요, 아답터쪽에서 몇일 동안 끙끙 앓고 있네요^^;;
그냥가자님이 많은 조언을 해주셔서 안드로이드 소스를 보고 흐름을 이해하는데 큰 도움이 되었습니다.
막상 수정을 하려고 하니 일단 현재 코드의 호출 스테이트를 정리하려고 로그를 찍었더니 다음과 같이나오더군요
*CustomViewBinder :: 로그
pos:[값] ( 값- cursor.getPosition() ), index:[값]( 값 - columnIndex)
08-12 01:13:08.352: INFO/ActivityManager(57): Displayed activity com.android.manager/.manager: 520 ms (total 520 ms)
08-12 01:13:11.893: INFO/ActivityManager(57): Starting activity: Intent { cmp=com.android.manager/.manager }
08-12 01:13:12.163: INFO/[log](265): getView
08-12 01:13:12.163: INFO/[log](265): newView
08-12 01:13:12.173: INFO/[log](265): CustomViewBinder::pos:[0] index:[5]
08-12 01:13:12.173: INFO/[log](265): CustomViewBinder::pos:[0] index:[6]
08-12 01:13:12.203: INFO/[log](265): CustomViewBinder::pos:[0] index:[3]
08-12 01:13:12.203: INFO/[log](265): CustomViewBinder::pos:[0] index:[4]
08-12 01:13:12.212: INFO/[log](265): getView
08-12 01:13:12.212: INFO/[log](265): CustomViewBinder::pos:[1] index:[5]
08-12 01:13:12.212: INFO/[log](265): CustomViewBinder::pos:[1] index:[6]
08-12 01:13:12.232: INFO/[log](265): CustomViewBinder::pos:[1] index:[3]
08-12 01:13:12.232: INFO/[log](265): CustomViewBinder::pos:[1] index:[4]
08-12 01:13:12.232: INFO/[log](265): getView
08-12 01:13:12.244: INFO/[log](265): CustomViewBinder::pos:[2] index:[5]
08-12 01:13:12.254: INFO/[log](265): CustomViewBinder::pos:[2] index:[6]
08-12 01:13:12.263: INFO/[log](265): CustomViewBinder::pos:[2] index:[3]
08-12 01:13:12.263: INFO/[log](265): CustomViewBinder::pos:[2] index:[4]
08-12 01:13:12.272: INFO/[log](265): getView
08-12 01:13:12.272: INFO/[log](265): CustomViewBinder::pos:[3] index:[5]
08-12 01:13:12.272: INFO/[log](265): CustomViewBinder::pos:[3] index:[6]
08-12 01:13:12.282: INFO/[log](265): CustomViewBinder::pos:[3] index:[3]
08-12 01:13:12.282: INFO/[log](265): CustomViewBinder::pos:[3] index:[4]
08-12 01:13:12.293: INFO/[log](265): getView
08-12 01:13:12.293: INFO/[log](265): CustomViewBinder::pos:[4] index:[5]
08-12 01:13:12.303: INFO/[log](265): CustomViewBinder::pos:[4] index:[6]
08-12 01:13:12.313: INFO/[log](265): CustomViewBinder::pos:[4] index:[3]
08-12 01:13:12.313: INFO/[log](265): CustomViewBinder::pos:[4] index:[4]
08-12 01:13:12.322: INFO/[log](265): getView
08-12 01:13:12.322: INFO/[log](265): CustomViewBinder::pos:[5] index:[5]
08-12 01:13:12.322: INFO/[log](265): CustomViewBinder::pos:[5] index:[6]
08-12 01:13:12.332: INFO/[log](265): CustomViewBinder::pos:[5] index:[3]
08-12 01:13:12.332: INFO/[log](265): CustomViewBinder::pos:[5] index:[4]
08-12 01:13:12.343: INFO/[log](265): getView
08-12 01:13:12.343: INFO/[log](265): CustomViewBinder::pos:[6] index:[5]
08-12 01:13:12.343: INFO/[log](265): CustomViewBinder::pos:[6] index:[6]
08-12 01:13:12.362: INFO/[log](265): CustomViewBinder::pos:[6] index:[3]
08-12 01:13:12.362: INFO/[log](265): CustomViewBinder::pos:[6] index:[4]
08-12 01:13:12.372: INFO/[log](265): getView
08-12 01:13:12.372: INFO/[log](265): CustomViewBinder::pos:[7] index:[5]
08-12 01:13:12.372: INFO/[log](265): CustomViewBinder::pos:[7] index:[6]
08-12 01:13:12.393: INFO/[log](265): CustomViewBinder::pos:[7] index:[3]
08-12 01:13:12.393: INFO/[log](265): CustomViewBinder::pos:[7] index:[4]
08-12 01:13:12.404: INFO/[log](265): getView
08-12 01:13:12.413: INFO/[log](265): CustomViewBinder::pos:[8] index:[5]
08-12 01:13:12.413: INFO/[log](265): CustomViewBinder::pos:[8] index:[6]
08-12 01:13:12.423: INFO/[log](265): CustomViewBinder::pos:[8] index:[3]
08-12 01:13:12.423: INFO/[log](265): CustomViewBinder::pos:[8] index:[4]
08-12 01:13:12.433: INFO/[log](265): getView
08-12 01:13:12.442: INFO/[log](265): CustomViewBinder::pos:[9] index:[5]
08-12 01:13:12.442: INFO/[log](265): CustomViewBinder::pos:[9] index:[6]
08-12 01:13:12.452: INFO/[log](265): CustomViewBinder::pos:[9] index:[3]
08-12 01:13:12.452: INFO/[log](265): CustomViewBinder::pos:[9] index:[4]
08-12 01:13:12.462: INFO/[log](265): getView
08-12 01:13:12.462: INFO/[log](265): CustomViewBinder::pos:[10] index:[5]
08-12 01:13:12.462: INFO/[log](265): CustomViewBinder::pos:[10] index:[6]
08-12 01:13:12.482: INFO/[log](265): CustomViewBinder::pos:[10] index:[3]
08-12 01:13:12.482: INFO/[log](265): CustomViewBinder::pos:[10] index:[4]
08-12 01:13:12.503: INFO/[log](265): getView
08-12 01:13:12.503: INFO/[log](265): CustomViewBinder::pos:[0] index:[5]
08-12 01:13:12.513: INFO/[log](265): CustomViewBinder::pos:[0] index:[6]
08-12 01:13:12.523: INFO/[log](265): CustomViewBinder::pos:[0] index:[3]
08-12 01:13:12.523: INFO/[log](265): CustomViewBinder::pos:[0] index:[4]
08-12 01:13:12.532: INFO/[log](265): getView
08-12 01:13:12.532: INFO/[log](265): newView
08-12 01:13:12.542: INFO/[log](265): CustomViewBinder::pos:[1] index:[5]
08-12 01:13:12.542: INFO/[log](265): CustomViewBinder::pos:[1] index:[6]
08-12 01:13:12.552: INFO/[log](265): CustomViewBinder::pos:[1] index:[3]
08-12 01:13:12.552: INFO/[log](265): CustomViewBinder::pos:[1] index:[4]
08-12 01:13:12.563: INFO/[log](265): getView
08-12 01:13:12.563: INFO/[log](265): newView
08-12 01:13:12.573: INFO/[log](265): CustomViewBinder::pos:[2] index:[5]
08-12 01:13:12.573: INFO/[log](265): CustomViewBinder::pos:[2] index:[6]
08-12 01:13:12.583: INFO/[log](265): CustomViewBinder::pos:[2] index:[3]
08-12 01:13:12.593: INFO/[log](265): CustomViewBinder::pos:[2] index:[4]
08-12 01:13:12.593: INFO/[log](265): getView
08-12 01:13:12.593: INFO/[log](265): newView
08-12 01:13:12.603: INFO/[log](265): CustomViewBinder::pos:[3] index:[5]
08-12 01:13:12.603: INFO/[log](265): CustomViewBinder::pos:[3] index:[6]
08-12 01:13:12.612: INFO/[log](265): CustomViewBinder::pos:[3] index:[3]
08-12 01:13:12.622: INFO/[log](265): CustomViewBinder::pos:[3] index:[4]
08-12 01:13:12.622: INFO/[log](265): getView
08-12 01:13:12.632: INFO/[log](265): newView
08-12 01:13:12.642: INFO/[log](265): CustomViewBinder::pos:[4] index:[5]
08-12 01:13:12.642: INFO/[log](265): CustomViewBinder::pos:[4] index:[6]
08-12 01:13:12.653: INFO/[log](265): CustomViewBinder::pos:[4] index:[3]
08-12 01:13:12.653: INFO/[log](265): CustomViewBinder::pos:[4] index:[4]
08-12 01:13:12.664: INFO/[log](265): getView
08-12 01:13:12.664: INFO/[log](265): newView
08-12 01:13:12.673: INFO/[log](265): CustomViewBinder::pos:[5] index:[5]
08-12 01:13:12.673: INFO/[log](265): CustomViewBinder::pos:[5] index:[6]
08-12 01:13:12.683: INFO/[log](265): CustomViewBinder::pos:[5] index:[3]
08-12 01:13:12.693: INFO/[log](265): CustomViewBinder::pos:[5] index:[4]
08-12 01:13:12.693: INFO/[log](265): getView
08-12 01:13:12.693: INFO/[log](265): newView
08-12 01:13:12.703: INFO/[log](265): CustomViewBinder::pos:[6] index:[5]
08-12 01:13:12.703: INFO/[log](265): CustomViewBinder::pos:[6] index:[6]
08-12 01:13:12.713: INFO/[log](265): CustomViewBinder::pos:[6] index:[3]
08-12 01:13:12.724: INFO/[log](265): CustomViewBinder::pos:[6] index:[4]
08-12 01:13:12.724: INFO/[log](265): getView
08-12 01:13:12.733: INFO/[log](265): newView
08-12 01:13:12.743: INFO/[log](265): CustomViewBinder::pos:[7] index:[5]
08-12 01:13:12.743: INFO/[log](265): CustomViewBinder::pos:[7] index:[6]
08-12 01:13:12.753: INFO/[log](265): CustomViewBinder::pos:[7] index:[3]
08-12 01:13:12.753: INFO/[log](265): CustomViewBinder::pos:[7] index:[4]
08-12 01:13:12.762: INFO/[log](265): getView
08-12 01:13:12.762: INFO/[log](265): newView
08-12 01:13:12.774: INFO/[log](265): CustomViewBinder::pos:[8] index:[5]
08-12 01:13:12.774: INFO/[log](265): CustomViewBinder::pos:[8] index:[6]
08-12 01:13:12.795: INFO/[log](265): CustomViewBinder::pos:[8] index:[3]
08-12 01:13:12.802: INFO/[log](265): CustomViewBinder::pos:[8] index:[4]
08-12 01:13:12.802: INFO/[log](265): getView
08-12 01:13:12.802: INFO/[log](265): newView
08-12 01:13:12.815: INFO/[log](265): CustomViewBinder::pos:[9] index:[5]
08-12 01:13:12.823: INFO/[log](265): CustomViewBinder::pos:[9] index:[6]
08-12 01:13:12.833: INFO/[log](265): CustomViewBinder::pos:[9] index:[3]
08-12 01:13:12.833: INFO/[log](265): CustomViewBinder::pos:[9] index:[4]
08-12 01:13:12.843: INFO/[log](265): getView
08-12 01:13:12.843: INFO/[log](265): newView
08-12 01:13:12.852: INFO/[log](265): CustomViewBinder::pos:[10] index:[5]
08-12 01:13:12.852: INFO/[log](265): CustomViewBinder::pos:[10] index:[6]
08-12 01:13:12.862: INFO/[log](265): CustomViewBinder::pos:[10] index:[3]
08-12 01:13:12.862: INFO/[log](265): CustomViewBinder::pos:[10] index:[4]
위에 빨간색 라인이 문제점입니다.
getView를 해서 convertView가 없으면 newView를 호출하여 새로 생성하고, 없으면 그대로 이용, 그다음 바인드 뷰를 호출하는데,
바인드 뷰에서는 제가 setBind로 연결해놓은 CustomViewBinder를 호출하는 흐름입니다.
처음 newView를 제외한 것은 제가 생각한 흐름대로 되었는데 저 빨간색 부분은 생각치 않은 호출이 이루어지더군요.
첫번째 Row를 getView 하고 newView를 하고나서 Cursor의 currentPos값을 변경하면서 계속 첫번째 row의 getView를 호출하는 것 같은데 이게 왜 이렇게 되야하는지 저는 도무지 이해가 안 가네요.
이거 버그인 것 같기도한데, 혹시 Row를 생성하는 상위 호출 클래스와 함수가 무엇인지 알 수 있을까요?
바로 소스를 봤는데 measureHeightOfChildren 이 함수가 optainView를 호출하여 optaionView가 getView를 호출하는 것을 확인하였습니다. 결국 초기에 보여질 리스트 사이즈를 체크 하기위하여 measureHeightOfChildren 이 함수를 호출하고 첫번째 생성된 row View를 가지고 루프를 돌면서 maxHeight를 넘거나 아이템 갯수가 다될때까지 체크하여 그 높이를 넘기는 과정에서 getView를 호출하게된다는 거군요...
이 결론은 동적으로 만들기 위해서는 그냥 View갯수가 있거나 없거나를 체크해서 뷰만 넘기는 소스로는 안 된다는 것 이 되다는 말이되네요 ㅠ getView를 할 때 getView안에 아이템들은 초기화해서 다시 add 시키는 수밖에 없다는 방법밖에 없겠네요.
아무튼 공부하는데 많은 도움이 되었습니다. 감사드립니다.^^
하지만 이것은 직접 추가하는 문장은 아니구요.
Height를 알기위해서 한번쭉 돌리는겁니다. 아마 이거땜시 나올겁니다.
이넘이 obtainView라는 넘을 호출하고 또 obtainView가 getView를 호출하는데
obtainView는 재활용 가능한 View를 관리해서 (Recycle 이라고 하는데) getView를 다르게 부르는군요.