2013-07-25 58 views
1

我在处理AutoCompleteTextViews时遇到了一个奇怪的问题。 我有以下的布局我的项目:当包含切换按钮时,AutoCompleteTextView项目不可点击

<?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:minHeight="48dp" 
android:orientation="horizontal" 
android:padding="8dp" > 

<TextView 
    android:id="@+id/name" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:text="Some place I already visited" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<ToggleButton android:id="@+id/starred" 
    android:layout_width="32dp" 
    android:layout_height="32dp" 
    android:layout_gravity="center" 
    android:background="@drawable/starred" 
    android:textOn="" 
    android:textOff=""/> 
</LinearLayout> 

现在我的适配器设置切换按钮的可见性的一些项目走了,其他为可见。如果它没有按预期工作,您可以单击它们,并将文本放入AutoCompleteTextView中,但在可见ToggleButton的情况下,项目不会响应触摸。尽管你可以与ToggleButton进行交互。

有没有办法使这个工作与AutoCompleteTextViews或我必须使用另一种类型的视图。

+0

简单的使'ToggleButton'不可聚焦(使用'android:focusable =“false'或者在代码'btn.setFocusable(false)')。 – Luksprog

+0

@Luksprog谢谢你的完美工作,如果你将它作为回答我会高兴地接受它 – user2055996

回答

1

简单地使行ToggleButton不可聚焦(与android:focusable="false"或在代码中,在适配器中,btn.setFocusable(false))。