【发布时间】:2013-10-26 17:19:24
【问题描述】:
在有人将此问题标记为重复之前,我必须说我已经知道这个问题已经被问过好几次了,但每次我尝试都失败了。
所以我在左侧有一个日期列表视图,我想在右侧显示数据,我想创建一个可以显示选择了哪个项目的列表视图,以便我知道我选择了哪个日期。 到目前为止,我已经尝试过;
在列表视图上我添加了android:choiceMode="singleChoice";
<ListView
android:id="@+id/listTglRMPasien"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_above="@+id/btnObatAlkes"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:choiceMode="singleChoice">
</ListView>
在列表视图的项目上我添加了android:background="@drawable/list_selector";
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtListRekamMedikTanggal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:background="@drawable/list_selector"/>
<TextView
android:id="@+id/txtListRekamMedikTabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/emptyString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:visibility="gone" />
</LinearLayout>
在 list_selector 上
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_launcher" android:state_activated="false"/>
<item android:drawable="@drawable/ic_launcher" android:state_pressed="false"/>
<item android:drawable="@drawable/blue" android:state_pressed="true"/>
<item android:drawable="@drawable/blue" android:state_activated="true"/>
</selector>
请注意这里的 ic_launcher 和 blue 是 png 文件,它应该是“@drawable/listitem_pressed”和“@drawable/solid_white”,我从here 找到了这个答案
但不知何故它出错了,上面写着No resource found that matches the given name,我认为缺少某些东西,所以我将其更改为 png 文件
无论如何,当我尝试运行它时,无论我是否选择它,它总是显示ic_launcher,它永远不会显示blue。
【问题讨论】:
标签: android listview android-listview