0

我目前正在研究具有兩個片段,一個列表片段和一個詳細片段的Android平板電腦應用程序。Android列表查看所選項目樣式直到用戶滾動才顯示

我想讓我的列表與人物和電子郵件類似,當選擇的項目背景變化,三角形位於列表的右側。

我目前在設置列表中所選項目的背景時遇到困難。 正如我在列表視圖中所理解的,我應該將android:listSelector設置爲drawable,並且都應該可以工作。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingLeft="8dp" 
> 

    <ListView android:id="@id/android:list" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"    
       android:layout_weight="1" 
       android:listSelector="@drawable/selected_background" 
       /> 


    <TextView android:id="@id/android:empty" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="No data. Please check your internet connection." android:gravity="center"/> 
</LinearLayout> 


<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <solid android:color="@color/hukd_orange_faded" /> 
</shape> 

當我這樣做時,彩色項目的背景不會改變,直到我開始滾動列表。不僅如此,背景閃爍並且經常回到標準背景顏色。

我看了網上,看起來有一個Holo.light的問題,如下所示Android list selector gets stuck when using Theme.Light 我已經嘗試了兩種狀態,但問題仍然存在。

+0

selected_background drawable引用底部的形狀。 – bencallis 2012-02-01 00:50:55

回答

3

我終於設法解決了這個問題。

所有這一切,需要的是以下兩行

listView = getListView(); 
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

現在的工作原理類似於郵件和人民ICS平板電腦。

相關問題