Categories: Android

[안드로이드] ListView에서 addFooterView 했을 때 보이지 않는 문제

 ListView 에는 addFooterView라는 것이 있습니다. 안드로이드 개발자 사이트를 보면 아래와 같이 설명이 되어 있습니다.







public void addFooterView (View v)


Since: API Level 1



Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.


NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.



Parameters





v The view to add.


public void addFooterView (View v, Object data, boolean isSelectable)


Since: API Level 1



Add a fixed view to appear at the bottom of the list. If addFooterView is called more than once, the views will appear in the order they were added. Views added using this call can take focus if they want.


NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.



Parameters











v The view to add.
data Data to associate with this view
isSelectable true if the footer view can be selected

출처 : http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)

 보니까 setAdapter 전에 호출을 해야 된다고 합니다. 제가 원하는 것은 setAdapter 후에도 정상적으로 해당 함수가 동작하는이었습니다. 그래서 테스트를 해보니 setAdapter 전에 dummy layout을 하나 add 해놓으면 그 뒤로 추가하는 것은 문제가 없다는 것을 발견하였습니다. 즉 setAdapter 후에도 addFooterView와 같은 것이 동작하도록 하려면 우선 dummy layout을 하나 만들어야 합니다. 예를 들면 아래와 같습니다.





<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout

xmlns:android=”http://schemas.android.com/apk/res/android”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”>

</LinearLayout>

 setAdapter 함수를 호출하기 전에 이러한 layout 파일을 하나 addFooterView 하도록 합니다. add를 하더라도 내용이 아무 것도 없기 때문에 화면에 보이지 않습니다. 이렇게 하면 setAdapter 후에 addFooterView를 해도 정상적으로 해당 기능이 동작하는 것을 보실 수 있으실 것 입니다. 하지만 addHeaderView의 경우 비슷한 기능을 하는 함수인데 아래 코드 때문에 이와 같은 동작이 불가능 한 것 같습니다.





if (mAdapter != null) { throw new IllegalStateException( “Cannot add header view to list — setAdapter has already been called.”); }

.

– 안드로이드 2.1 & 2.2 버전에서 테스트 되었습니다.

dingpong

Share
Published by
dingpong

Recent Posts

LFS error at git checkout in Jenkins

Problem stdout: stderr: Downloading xxxx.a (83 MB) error: git-lfs smudge -- 'xxxx.a' died of signal…

3년 ago

플레이모빌 크리스마스 XXL 6629 산타 해외직구 구매가 배송비

https://www.playmobil.de/playmobil-xxl-weihnachtsmann/6629.html 구매가 : 48.49 유로 (플레이모빌 독일 홈페이지) 결제하는데 안되서 PayPal 로 결제하니 잘 잔행…

3년 ago

코카콜라 제로 355ml 72캔 구매가 (캔당 453원)

롯데온에서 355ml 24캔 롯데카드로 구매시 13,210원 https://www.lotteon.com/p/product/PD36294 APP으로 35,000원 이상 구매시 7,000 포인트 적립 행사…

4년 ago

경동나비엔 온수매트 EQM541-QS (퀸사이즈) 구입가

구입 매장 : 현대 홈쇼핑 (홈쇼핑 방송 중) 모바일 앱 http://www.hyundaihmall.com/front/pda/itemPtc.do?slitmCd=2114353981 최종 결제 가격 :…

4년 ago

PostMessage에 shared_ptr과 같은 스마트 포인터 넣기

PostMessage의 WPARAM 이나 LPARAM 으로 shared_ptr 와 같은 스마트 포인터 객체를 넘기고 싶은 경우가 있습니다.…

4년 ago

RC2255 – named STRINGTABLEs are not allowed

Visual Studio 에서 작업 중 이러한 컴파일 에러가 발생한 케이스가 있었습니다. 이 경우에는 .rc 파일에…

4년 ago