Android版的TableView为ItemView控件中的ListView无法点击 [英] Android TableView as itemview in ListView not clickable

查看:229
本文介绍了Android版的TableView为ItemView控件中的ListView无法点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用同一个ListView自定义适配器,并使用自定义布局提供名单itemviews。我的布局是这样的。

I am using a custom adapter with a ListView and using a custom layout to supply the list itemviews. My layout is like this

> LinearLayout
    > TableView
        > TableRow
            > TextView
            > TextView

这将导致不响应点击列表中的项目,但如果我编辑布局以下它的工作原理

This results in list items that do not respond to clicks but if I edit the layout to the following it works

> LinearLayout
    > TextView
    > TextView

所以我知道,有什么错我的适配器和活动。

So I know that there is nothing wrong with my Adapter and Activity.

我曾尝试加入的android:descendantFocusability =blocksDescendants来的最高水平的线性布局,在这一问题<建议href=\"http://stackoverflow.com/questions/2985890/listview-items-not-clickable-with-horizontalscrollview-inside\">ListView里面

I have tried adding android:descendantFocusability="blocksDescendants" to the top level linear layout as suggested in this question ListView items not clickable with HorizontalScrollView inside

我也尝试添加的android:点击=真正的机器人:可聚焦=真正的来在的TableView 但这并不能工作。

I have also tried adding android:clickable="true" and android:focusable="true" to the TableView but this does not work either.

任何想法?

修改

布局XML源$ C ​​$ C

layout XML source code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
    <TableLayout  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    >
        <TableRow 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:clickable="true"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:gravity="center_vertical">
            <TextView 
                android:id="@+id/ITEMVIEW_TEXT2_lblText" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp" 
                android:paddingRight="5dp"
                android:paddingLeft="15dp"
                />
            <TextView 
                android:id="@+id/ITEMVIEW_TEXT2_lblText2" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textColor="#ff385487"
                android:gravity="right"
                android:paddingRight="15dp"
                />
        </TableRow>
    </TableLayout>
</LinearLayout>


修改

我曾尝试加入机器人:可聚焦=FALSE的建议<一href=\"http://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items\">here和<一个href=\"http://stackoverflow.com/questions/3611551/textview-and-button-in-each-row-and-onlistitemclick\">here但这并不能工作。

I have tried adding android:focusable="false" as suggested here and here but that does not work either.

修改

我真正想在这里实现了布置文本之一对准左边和其他权利的两列。我想出了一个更好的布局来实现这一点,不使用的TableView,所以我的ListView项目保持点击,它也使用较少的意见,这也将是更有效的,这是它

All I really wanted to achieve here was laying out two columns of text one aligned left and the other right. I figured out a better layout to achieve this that does not use TableView so my ListView items remain clickable, it also uses less views so it will also be more efficient, this is it

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
            <TextView 
                android:id="@+id/ITEMVIEW_TEXT2_lblText" 
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:textSize="20sp" 
                android:paddingRight="5dp"
                android:paddingLeft="15dp"
                />
            <TextView 
                android:id="@+id/ITEMVIEW_TEXT2_lblText2" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textColor="#ff385487"
                android:gravity="right"
                android:paddingRight="15dp"
                />
</LinearLayout>

这是不是TableView中的决策的ListView项非可点击的问题的解决方案,但我的情况下,其他人是希望找出如何做一个类似的布局这里要注意了。

This is not a solution to the problem of TableView making ListView items non clickable but I have noted it here in case anyone else is looking to figure out how to do a similar layout.

推荐答案

我是用TableLayout和的TableRow的组合绊倒类似的问题。

I was stumbling over a similar issue using the combination of TableLayout and TableRow.

我的解决方案是以下几点:
的TableRow似乎没有自己的选择也正因为如此,即使你把它定义为可以点击的,聚焦的,你永远不会看到一个视觉上的差异。
我分配了一个背景,那就是相当于所使用的GridView的一个的TableRow(可下Android的SDK窗口的SDK中找到\\ \\平台Android的10 \\ DATA \\水库\\绘制\\ grid_selector_background.xml)。

My solutions was the following: TableRow seems not to have its own Selector and because of this even if you define it as clickable and focusable, you will never see a visual difference. I assigned a background to the TableRow that is comparable to the one that is used by a GridView (can be found in the SDK under android-sdk-windows\platforms\android-10\data\res\drawable\grid_selector_background.xml).

此后,它是完全可聚焦和点击。

Afterwards it was perfectly focusable and clickable.

这篇关于Android版的TableView为ItemView控件中的ListView无法点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆