2
我想突出默認情況下我的列表視圖中的位置。Android的列表視圖選擇默認項目
下面是代碼: 我的列表視圖聲明:
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
項目列表聲明
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
在我的自定義選擇,我有:
<item
android:drawable="@android:color/holo_green_light"
android:state_selected="true"/>
現在我想用默認的綠色標記在我的列表視圖中的一個位置。 Java代碼:
listview.setSelector(R.drawable.listselector);
listview.setSelection(20);
但所選元素不與綠顏色突出顯示。我嘗試了很多提出的解決方案,但沒有成功。 任何想法? 在此先感謝。
它不會以這種方式工作..仍然沒有突出 – Steffi 2013-05-09 08:40:47
請分享您的代碼的其餘部分。完整的選擇器XML和您從中設置選擇的類。你是否記得在將它添加到XML之後刪除'listview.setSelector(R.drawable.listselector);'? – tbkn23 2013-05-09 10:03:13