[英]Disable response of root view in android
我有幾行的ListView
。 每行包含7個對onClick()
事件作出反應的TextViews
。
這一切都很好,但是當用戶單擊行的空白處(沒有TextView
捕獲onClick()
事件)時, 根視圖 LinearLayout
- get突出顯示 。
當然,這是正常的行為,但是如果單擊此處沒有任何反應,則我不想突出顯示“線性布局”。 有什么方法可以禁用此行為,但是可以繼續捕獲 TextView
上的onClick()事件嗎?
(onClick偵聽器在適配器的getView()方法中設置)
這里是xml文件的一些摘錄。 可以看到,我已經嘗試了一些方法,但是它們不起作用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:longClickable="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false">
<TextView
android:id="@+id/listelement_weekoverview_tv_mo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
android:background="@drawable/weeklylist_rndrectangle"
android:gravity="center_horizontal"
android:singleLine="false"
android:textColor="@color/appcolor_red_base" />
...
</LinearLayout>
未點擊的版本 點擊版本
我找到了解決方案。
只需像這樣在您的自定義適配器中覆蓋isEnabled (int position)
方法:
@Override
public boolean isEnabled (int position) {
return false;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.