本文介绍了Android的ListView控件SetSelector问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在code正在创建一个ListView是这样的:

I have a ListView being created in code like this:

ListView lv  = new ListView(this);
lv.setId(GENERALLISTVIEWID);
lv.setBackgroundColor(0x333333);
lv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setDivider(null);
lv.setDividerHeight(0);
lv.setSelector(R.drawable.mainselector);

在我的 mainselector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/orange" android:state_pressed="true"/>
    <item android:drawable="@color/white" android:state_selected="true"/>
</selector>

问题是,当我选择行,单元格下方的列表视图全部亮起橙色。为什么不只是单行变成橙色?

The problem is, when I select the row, the entire listview underneath the cells lights up orange. Why is not just the single row turning orange?

推荐答案

好吧,我已经解决了这个问题,我正在运用的资源,我的整个的ListView,而不是我的ListView行的错误。

Okay I have solved the issue, I was making the mistake of applying the resource to my entire ListView instead of to my ListView row.

现在还是比较明显的。我已经申请mainselector为背景,以我的ListView cell.xml来代替。

Now it is quite obvious. I have applied mainselector as the background to my ListView cell.xml instead.

这篇关于Android的ListView控件SetSelector问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 19:22