0

我的第一个问题在这里!我需要一些帮助来点击我的 TextViews。它们被插入到动态添加到 TableLayout 的 TableRow 中。它们几乎占据了 TableRows 的所有空间(减去填充),因此我无法做到,因此 TableRows ClickListener 注册了点击而不是 TextViews。只有当我单击行的边缘(同样是填充)时,它才会起作用。

这是要插入到预定义 TableLayout 中的行的 XML,其中包含我需要单击的文本视图。

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:padding="5dp"
android:clickable="true"
 >

<TextView
    android:id="@+id/contactId"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryLastName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryFirstName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent" 

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

</TableRow>

我一直在寻找解决方案,我发现的唯一解决方案是将所有“可点击”和可聚焦属性设置为 false,但这些都不起作用。

真的应该有一个简单的解决方案,对吧!?

4

1 回答 1

0

尝试这个

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:padding="5dp"
android:descendantFocusability="blocksDescendants" >

<TextView
    android:id="@+id/contactId"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryLastName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryFirstName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent" 

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

</TableRow>
于 2013-12-04T13:27:13.760 回答