选定的ListView行设置背景 [英] Set background of a selected listview row
问题描述
我有被填充的位置,当你点击这个带来了就业机会,这个位置内完成一个位置的列表视图。当所有的工作已经完成,然后你点击一个OK按钮,现在在这一点上我想在ListView背景颜色选定位置的行改变。
我至今该按钮是什么
I have a listview which is populated with locations, When you click on a location this brings up jobs to be done within this location. When all jobs have been completed you then click on a ok button now at this point I want the selected location row in the listview background colour to change. What I have so far for the button
mOkBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
View listView = getActivity().findViewById(R.id.area_list);
listView.setBackgroundColor(Color.GREEN);
mArea.checkResult = CheckResult.OK;
mArea.checkTimeStamp = System.currentTimeMillis()/1000L;
showResults();
}
});
目前,这改变了整个列表视图绿色,但林不知道如何得到它改变的只是选定行。
At the moment this changes the whole listview green, but im not sure how to get it to change just the selected row.
THX
推荐答案
有关设置颜色,你需要一个选择。您可以使用Android的清单上设置此:listSelector属性为:
For setting the colour, you need a selector. You can set this on your list using the android:listSelector attribute as :
<ListView
android:id="@+id/foodlistview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:scrollbarFadeDuration="0"
android:divider="@android:color/white"
android:dividerHeight="2px"
android:listSelector="list_selector"
></ListView>
和list_selector.xml:
And list_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/item_disabled" />
<item android:state_pressed="true"
android:drawable="@drawable/item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/item_focused" />
</selector>
这篇关于选定的ListView行设置背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!