我偶然发现了 ListViews 的一个奇怪问题。
在模拟器中,当按下项目进行选择时,ListView 不会显示任何反馈。我想我已经在现实中看到了这一点,但我不确定。我希望列表项在按下时被选中(较暗的背景),以便用户可以看到他按下了哪个项目。
我必须编码吗?
RG
看到评论后,我尝试了以下方法:
我创建了一个文件 res/color/backgroundstate.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:color="#888"/>
<item android:state_pressed="true"
android:color="#888"/>
<item android:color="#eee"/>
</selector>
然后我在 listitem.xml 中使用它作为背景色
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/helptextcolor"
android:background="@color/backgroundstate"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
当我显示 ListView 时
ArrayAdapter adapter=new ArrayAdapter<String>(this,R.layout.listitem,names);
LV.setAdapter(adapter);
LV.invalidate();
程序崩溃。
有与此相关的三个例外。但问题似乎是最后一个XMLPullParserException:
<item> tag needs a drawable.
现在?