Android:将页脚添加到水平自定义列表视图

时间:2015-03-10 09:13:18

标签: android listview android-listview horizontal-scrolling

我正在开发一个应用程序,我在其中使用带有自定义适配器的水平列表视图。我使用从以下链接获得的库来实现水平列表视图。

Horizontal List View

这很好用。因为我能够看到水平列表视图,并且我还能够在点击列表项时应用操作。

问题是:我想将页脚视图应用到我在链接和库的帮助下实现的列表视图。当页脚可见时,我想调用Web服务从服务器获取数据。我还在以下列表中应用了onScrollListener()。

onScrollListener()工作正常。当最后一项出现时,我也可以调用Web服务。但我的网络服务在我的最后一项完全可见之前调用,在我的网络服务调用的最后一项的部分可见性上。此外,如果我稍微滚动列表,那么Web服务再次调用相反的方向。

当我上面列表的最后一项完全可见或将页脚添加到上面的列表时,我该怎么办调用网络服务

我尝试了添加页脚的常规方法:

footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.list_footer_view, null, false);
twoWayListView.addView(footerView);

但它会出错。

03-10 14:37:05.173: D/ACRA(23881): Wait for Toast + worker ended. Kill Application ? true
03-10 14:37:05.178: E/ACRA(23881): com.example.demolist fatal error : Unable to start activity ComponentInfo{com.example.demolist/com.example.demolist.MyActivity}: java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
03-10 14:37:05.178: E/ACRA(23881): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demolist/com.example.demolist.MyActivity}: java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread.access$800(ActivityThread.java:151)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
03-10 14:37:05.178: E/ACRA(23881):  at android.os.Handler.dispatchMessage(Handler.java:110)
03-10 14:37:05.178: E/ACRA(23881):  at android.os.Looper.loop(Looper.java:193)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread.main(ActivityThread.java:5299)
03-10 14:37:05.178: E/ACRA(23881):  at java.lang.reflect.Method.invokeNative(Native Method)
03-10 14:37:05.178: E/ACRA(23881):  at java.lang.reflect.Method.invoke(Method.java:515)
03-10 14:37:05.178: E/ACRA(23881):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
03-10 14:37:05.178: E/ACRA(23881):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
03-10 14:37:05.178: E/ACRA(23881):  at dalvik.system.NativeStart.main(Native Method)
03-10 14:37:05.178: E/ACRA(23881): Caused by:     java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
03-10 14:37:05.178: E/ACRA(23881):  at android.widget.AdapterView.addView(AdapterView.java:452)
03-10 14:37:05.178: E/ACRA(23881):  at com.example.demolist.MyActivity.initializeScreen(MyActivity.java:100)
03-10 14:37:05.178: E/ACRA(23881):  at com.example.demolist.MyActivity.onCreate(MyActivity.java:73)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.Activity.performCreate(Activity.java:5264)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
03-10 14:37:05.178: E/ACRA(23881):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
03-10 14:37:05.178: E/ACRA(23881):  ... 11 more
03-10 14:37:05.178: I/ACRA(23881): Finishing the last Activity prior to killing the Process
03-10 14:37:05.186: I/ACRA(23881): Finished class com.example.demolist.MyActivity
03-10 14:37:05.186: I/Process(23881): Sending signal. PID: 23881 SIG: 9

请建议我该怎么做。

0 个答案:

没有答案