我在 android 版本 4.3 中为 listview 跨应用程序使用 listview 添加/删除页脚? [英] I am using the listview add/remove footer for listview cross app in android version 4.3?

查看:25
本文介绍了我在 android 版本 4.3 中为 listview 跨应用程序使用 listview 添加/删除页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于 ListView 添加页脚视图并删除页脚,它在 android 4.4 以上版本中工作正常但是 android 4.3 及以下版本的问题我正在使用以下代码添加页脚

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 am using the following code for adding the footer

listfortestmyfeed.addFooterView(footerView);

并删除以下代码的页脚

listfortestmyfeed.removeFooterView(footerView);

删除在我的 logcat 中显示类转换异常的页脚

remove footer showing class cast exception in my logcat

 07-11 20:07:49.665: E/ACRA(22818): com.sample.activities fatal error : com.sample.adapters.MyfeedAdapter cannot be cast to android.widget.HeaderViewListAdapter
    07-11 20:07:49.665: E/ACRA(22818): java.lang.ClassCastException: com.sample.adapters.MyfeedAdapter cannot be cast to android.widget.HeaderViewListAdapter
    07-11 20:07:49.665: E/ACRA(22818):  at android.widget.ListView.removeFooterView(ListView.java:390)
    07-11 20:07:49.665: E/ACRA(22818):  at com.sample.fragments.MyfeedNewFragment$FollowingBloopsdoinback.onPostExecute(MyfeedNewFragment.java:172)
    07-11 20:07:49.665: E/ACRA(22818):  at com.sample.fragments.MyfeedNewFragment$FollowingBloopsdoinback.onPostExecute(MyfeedNewFragment.java:1)
    07-11 20:07:49.665: E/ACRA(22818):  at android.os.AsyncTask.finish(AsyncTask.java:631)
    07-11 20:07:49.665: E/ACRA(22818):  at android.os.AsyncTask.access$600(AsyncTask.java:177)
    07-11 20:07:49.665: E/ACRA(22818):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
    07-11 20:07:49.665: E/ACRA(22818):  at android.os.Handler.dispatchMessage(Handler.java:99)
    07-11 20:07:49.665: E/ACRA(22818):  at android.os.Looper.loop(Looper.java:137)
    07-11 20:07:49.665: E/ACRA(22818):  at android.app.ActivityThread.main(ActivityThread.java:5103)
    07-11 20:07:49.665: E/ACRA(22818):  at java.lang.reflect.Method.invokeNative(Native Method)
    07-11 20:07:49.665: E/ACRA(22818):  at java.lang.reflect.Method.invoke(Method.java:525)
    07-11 20:07:49.665: E/ACRA(22818):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    07-11 20:07:49.665: E/ACRA(22818):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    07-11 20:07:49.665: E/ACRA(22818):  at dalvik.system.NativeStart.main(Native Method)

我没有发现错误请告诉我谁知道提前谢谢

i didn't findout the mistake please tell me anyone know advance thanks

推荐答案

这可能是由于在 ListView 上调用 setAdapter() before 调用 setFooterView().这在 4.4 之前的所有 Android 版本中都是必需的

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

实际上,直到我看到这个问题,我才知道 KitKat 已经放宽了此限制... :)

在 API 级别 15 的 addFooterView() 源代码中:

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.

同时,KitKat,这个限制放宽了:

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.

如果你想兼容pre-4.4,你需要尊重调用顺序,即

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);

这篇关于我在 android 版本 4.3 中为 listview 跨应用程序使用 listview 添加/删除页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆