我现在用的是列表视图添加/删除页脚列表视图跨应用程序在Android版本4.3?
我用了的ListView
添加页脚视图,并在Android版本4.4中删除页脚它工作得很好以上
但问题在Android版本4.3及以下
我现在用的是下面的code添加页脚
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);
和删除页脚以下code
and remove footer following code
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)
我没有findout错误,请告诉我,任何人都知道 先感谢
i didn't findout the mistake please tell me anyone know advance thanks
这可能是通过调用引起 setAdapter()
在ListView中的在的调用 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
其实,我不知道这个限制已经放宽了奇巧,直到我看到了这个问题...:)的
在 addFooterView()
的API级别15来源:
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.
如果你想用pre-4.4兼容的,你需要尊重呼叫顺序,即
If you want to be compatible with pre-4.4, you need to respect the calling order, i.e.
-
addFooterView(页脚);
-
setAdapter(适配器);
-
removeFooterView(页脚);
addFooterView(footer);
setAdapter(adapter);
removeFooterView(footer);