XML在一个ListView选中列表项 [英] XML for Checked List Item in a ListView

查看:104
本文介绍了XML在一个ListView选中列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找全国各地的需要设置一个ListView使用复选框XML的例子。虽然我已经能够找到所需要的Java的code,列表项的XML仍然出奇难以捉摸。是否有良好的资源,以了解如何适当风格这些listItems中?

I've been searching all over for an example of the XML needed to setup a ListView to use a checkbox. While I've been able to find the Java code needed, the XML for the list items remains surprisingly elusive. Are there any good resources to learn how to style these listitems appropriately?

当我试图修改基本的XML文件我也有,我得到了以下错误:

When I tried modifying the base XML file I have, I got the following error:

java.lang.IllegalStateException:ArrayAdapter需要的资源ID是一个TextView

java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView

所以我不知道如何使用的不仅仅是一个TextView更多的元素在我自己创建它。所以目前,我使用发现这里作为一个ArrayAdapter的资源ID的整数值:
http://developer.android.com/reference/android/R.layout.html#simple_list_item_checked

So I'm not sure how to create it on my own using more elements than just a TextView. So currently, I am using the integer value found here as the resource ID for the ArrayAdapter: http://developer.android.com/reference/android/R.layout.html#simple_list_item_checked

它看起来像我想要什么,但我需要能够找到该资源和风格为我自己的需要的XML。任何帮助将大大AP preciated!

which looks like what I want, but I need to be able to find the XML for that resource and style it for my own needs. Any help would be greatly appreciated!

推荐答案

找到了!

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:checkMark="?android:attr/textCheckMark"
android:paddingLeft="6dip"
android:paddingRight="6dip"
/>

这篇关于XML在一个ListView选中列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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