用的ListView复选框 - 为什么复选框不显示? [英] ListView with checkbox - why the checkbox doesn't show?

查看:195
本文介绍了用的ListView复选框 - 为什么复选框不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ListView控件提供一个列表供用户选择。

下面是主要的code:

  SimpleAdapter适配器=新SimpleAdapter(本,通讯录,R.layout.list_contact,
                                          from_contacts,to_contacts);
listview_selected_contact.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listview_selected_contact.setAdapter(适配器);

我不知道为什么复选框不显示?
该程序正常运行只是不可见的复选框。
谁能帮助?

下面是XML:

 <?XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:方向=垂直
  机器人:layout_width =match_parent
  机器人:layout_height =match_parent>
  <的TextView的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=TextView的机器人:textAppearance =:机器人机器人ATTR / textAppearanceMedium?:ID =@ + ID /用户名>&LT ; / TextView的>< / LinearLayout中>


解决方案

它看起来像你的R.layout.list_contact不CheckedTextView。

请参阅 android.R.layout.simple_list_item_multiple_choice

我可以推荐你建立这是任何一个ViewGroup类儿童和接口可选中的implementator自定义视图。

I'm using the ListView to provide a list for the user to choose from.

Here is the main code:

SimpleAdapter adapter = new SimpleAdapter(this,contacts, R.layout.list_contact,
                                          from_contacts, to_contacts);
listview_selected_contact.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listview_selected_contact.setAdapter(adapter);

I wonder why the checkbox doesn't show? The program run properly just without the visible checkbox. Can anyone help?

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/username"></TextView>

</LinearLayout>

解决方案

It looks like that your R.layout.list_contact isn't CheckedTextView.

See source of android.R.layout.simple_list_item_multiple_choice

I can recommend you to build custom view which is child of any ViewGroup classes and implementator of interface Checkable.

这篇关于用的ListView复选框 - 为什么复选框不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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