Android的列表查看所选项目的风格没有出现,直到用户滚动 [英] Android List View selected item style not showing until user scrolls
问题描述
我目前的工作在Android平板电脑应用程序,它有两个片段,一个列表片段和细节片段。
I am currently working on an Android tablet application which has two fragments, a list fragment and a details fragment.
我试图让我的列表中有相似的地方选择的项目背景的变化和一个三角形放置在列表的右侧,当人们和电子邮件。
I am trying to make my list similar to People and Email where when selected the item background changes and a triangle is positioned on the right hand side of the list.
我目前遇到困难,在设置列表中选定项的背景。
正如我在列表视图明白我应该设置机器人:listSelector到绘制,所有应该工作
I am currently having difficulties setting the background of the item selected in the list. As I understand in the list view I should set android:listSelector to a drawable and all should work.
<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>
在我这个做彩色项的背景不会改变,直到我开始滚动列表。不仅如此,但背景闪烁,往往可以追溯到标准的背景颜色。
When I do this the background of the coloured item does not change until I start to scroll the list. Not only this but the background flickers and often goes back to the standard background colour.
我在网上看了看,似乎有一个与Holo.light一个问题,因为这里Android列表选择使用得到 Theme.Light卡住时,
我已经尝试了两种状态,但存在的问题依然存在。
I have looked online and it seems there is a problem with Holo.light as shown here Android list selector gets stuck when using Theme.Light I have tried two states but the problems still exist.
推荐答案
我终于设法解决这个问题。
I have finally managed to solve this problem.
所有这一切都需要的是以下两行
All that was required was the following two lines
listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
现在它的工作原理类似于邮件和人民为ICS平板电脑。
It now works similar to mail and people in ICS for tablets.
这篇关于Android的列表查看所选项目的风格没有出现,直到用户滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!