问题描述
我使用ListFrament,我想强调所选行。
I am using ListFrament and I want to highlight selected rows.
我的选择:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/gold" />
<item
android:state_selected="true"
android:drawable="@color/plum" />
<item
android:drawable="@color/medium_green" />
</selector>
在code在我ListFragment:
在onCreateActivity:
The code in my ListFragment:in onCreateActivity:
this.getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
上点击:
@Override
public void onListItemClick(ListView list, View v, int position, long id) {
super.onListItemClick(list, v, position, id);
String tag = this.getTag();
Log.d(TAG, "id, position " + id + " " + position);
list.setSelection(position);
}
不幸的是这不工作 - 它只是闪烁金,单击行的时候......我想那选定行保持突出显示...
unfortunately this does not work - it only blinks "gold", when clicking the row... I want that the selected row stays highlighted...
预先感谢您的回答,
推荐答案
试试这个
设置行类型的全局变量。我正在查看,因为它是通用的。
set a Global Variable of your row type. I am taking View as it is generic
View previous;
初始化鉴于onCreateView
initialize view in onCreateView
previous=new View(getContext);
当onListItemClick
做这样的
And when onListItemClick do like this
public void onListItemClick(ListView list, View v, int position, long id) {
super.onListItemClick(list, v, position, id);
String tag = this.getTag();
Log.d(TAG, "id, position " + id + " " + position);
previous.setSelected(false);
v.setSeleted(true);
previous=v;
}
试试这个,你回我在旧的应用程序使用这个...我将肯定工作..我希望这会帮助你。
Try this and Get back to I have used this in my old apps... I will work for sure.. I hope this will help you.
这篇关于ListFragment:高亮选中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!