添加的ImageView作为列表视图的头 [英] Add the imageview as the header of the listview

查看:81
本文介绍了添加的ImageView作为列表视图的头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发使用下面的链接,一个应用程序
自定义的ListView页眉

Hi I am developing one app using the below link Custom ListView With Headers

现在我的问题是我想要的图像设置为标题的listview.I是显示使用第二类Addsection的即的项目清单;

Now My question is i want to set the image as header for the listview.I am display the list of items using the second type of addsection i.e;

adapter.addSection("Security", new SimpleAdapter(this, security, R.layout.list_complex,  
            new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption })); 

我使用的图像视图,而不是在TextView的那个list_headre.xml.at时候我得到了以下异常

I am using the image view instead of textview in list_headre.xml.at that time i got the following exception

02-28 05:43:12.273: ERROR/ArrayAdapter(1212): You must supply a resource ID for a TextView
02-28 05:43:12.273: DEBUG/AndroidRuntime(1212): Shutting down VM
02-28 05:43:12.273: WARN/dalvikvm(1212): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
02-28 05:43:12.283: ERROR/AndroidRuntime(1212): Uncaught handler: thread main exiting due to uncaught exception
02-28 05:43:12.322: ERROR/AndroidRuntime(1212): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at chronicle.books.shopping.SeparatedListAdapter.getView(SeparatedListAdapter.java:97)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.AbsListView.obtainView(AbsListView.java:1274)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ListView.makeAndAddView(ListView.java:1668)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ListView.fillDown(ListView.java:637)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ListView.fillFromTop(ListView.java:694)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ListView.layoutChildren(ListView.java:1521)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.AbsListView.onLayout(AbsListView.java:1113)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ScrollView.onLayout(ScrollView.java:1108)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:900)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.View.layout(View.java:6830)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.ViewRoot.performTraversals(ViewRoot.java:996)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.os.Looper.loop(Looper.java:123)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.app.ActivityThread.main(ActivityThread.java:4363)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at java.lang.reflect.Method.invokeNative(Native Method)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at java.lang.reflect.Method.invoke(Method.java:521)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at dalvik.system.NativeStart.main(Native Method)
02-28 05:43:12.322: ERROR/AndroidRuntime(1212): Caused by: java.lang.ClassCastException: android.widget.ImageView
02-28 05:43:12.322: ERROR/AndroidRuntime(1212):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)

现在我要显示的图像作为标题,而不是TextView.For这个请给我一些code suggestions.Thanks提前

Now I want to display the image as header instead of TextView.For this please give me some code suggestions.Thanks in advance

推荐答案

ArrayAdapter 只支持的TextView 的意见。 按照该文档要使用比其他TextViews的东西阵列显示器,例如,ImageViews,还是有一些数据之外的toString()结果填补意见,覆盖getView(INT,查看,ViewGroup中)返回你想要查看的类型。

ArrayAdapter only supports TextView views. As per the docs: To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

如果你只是想要一个的ImageView 的头,我会在下面用我原来的答复。

If you just want a single ImageView in the header, I would use my original answer below.

原来的答复:使用方法<一个href=\"http://developer.android.com/reference/android/widget/ListView.html#addHeaderView%28android.view.View%29\"相对=nofollow> addHeaderView 的ListView ,只是传递一个 ImageView的

Original answer: Use the method addHeaderView in ListView and just pass in an ImageView.

这篇关于添加的ImageView作为列表视图的头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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