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

前端 未结 2 434
渐次进展
渐次进展 2020-12-30 05:43

I used to the ListView add the footer view and also remove footer its worked fine in android version 4.4 above but problem in android version 4.3 and below I a

2条回答
  •  天命终不由人
    2020-12-30 06:23

    This is probably caused by calling setAdapter() on the ListView before calling setFooterView(). This was necessary in all versions of Android prior to 4.4

    Actually, I didn't know this restriction had been relaxed for KitKat until I saw this question... :)

    In the sources of addFooterView() for API level 15:

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

    Meanwhile, it KitKat, this restriction was relaxed:

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

    If you want to be compatible with pre-4.4, you need to respect the calling order, i.e.

    1. addFooterView(footer);
    2. setAdapter(adapter);
    3. removeFooterView(footer);

提交回复
热议问题