Skip to content

Instantly share code, notes, and snippets.

@shau-lok
Created April 14, 2016 03:08
Show Gist options
  • Select an option

  • Save shau-lok/ae10f623b9f8b30ec343e4cc97b9e5aa to your computer and use it in GitHub Desktop.

Select an option

Save shau-lok/ae10f623b9f8b30ec343e4cc97b9e5aa to your computer and use it in GitHub Desktop.
Something wrong about listView.addFooterView() in the preVersion Android 4.4

Problem fixed from stackOverFlow

I am using the listview add/remove footer for listview cross app in android version 4.3?

Problem:

  • Android 4.4 以上 ListView 正常显示AddFooterView()内容
  • Android 4.3 以下 ListView 反而显示不出AddFooterView内容

Why:

probably caused by calling setAdapter() before addFooterView()

在 API 15 AddFooterView()源码的注释如下:

/*
 * 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.
 */

在 KitKat放松了这个限制,代码注释如下:

/*
 * Note: When first introduced, this method could only be called before
 * setting the adapter with {@link #setAdapter(ListAdapter)}. Starting with
 * {@link android.os.Build.VERSION_CODES#KITKAT}, this method may be
 * called at any time.

Fixed:

如果需要在 API 18 以下正常显示:

必须先调AddFooterView(),然后SetAdapter()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment