机器人:可点击="真"意思是,这不是点击? [英] android:clickable="true" mean's that it's not clickable?

查看:182
本文介绍了机器人:可点击="真"意思是,这不是点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它的一些自定义栏目一个ListView。每个部分都有它自己的头查看。我想在列表中的元素是可以点击的,但显然不希望部分标题来点击。因此,在XML的章节标题我加入机器人:可点击=假

I have a ListView with some custom sections in it. Each section has it's own header View. I want the elements in the list to be clickable, but obviously do not want the section headers to be clickable. So in the xml for the section headers I added android:clickable="false".

在调试我注意到,节头仍然回应我的 setOnItemClickListener()。然后我试着设置机器人:可点击=真正的的XML。果然,节头的看法不再对点击响应...

When debugging I noticed that the section headers were still responding to my setOnItemClickListener(). Then I tried setting android:clickable="true" in the XML. And sure enough, the section header views no longer respond to the clicks...

那么,什么是交易吗?为什么是它设置点击 = 告诉它,它是不会点击?我误解的东西吗?这里是我的XML:

So what is the deal here? Why is it that setting clickable = true telling it that it is NOT clickable? Am I misunderstanding something here? Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_text"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/black"
    android:background="@android:color/transparent"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:paddingLeft="30dp"
    android:clickable="true" />

如果我设置了点击=假在底部,那么这种观点开始到 setOnItemClickListener() ...

If I set that clickable="false" at the bottom, then this view begins to respond to the setOnItemClickListener()...

推荐答案

当您设置 OnItemClickListener ,事件 onItemClicked 将只能被称为如果 ListView控件的子不具有 OnClickListener 设置。点击设置为true,将提供子视图(在这种情况下,你的的TextView )和一个空 OnClickListener 。因为的TextView OnClickListener 设置了 OnItemClickListener 将不会被调用。

When you set the OnItemClickListener, the event onItemClicked will only be called if the child of the ListView does not have the OnClickListener set. Setting clickable to true will provide the child view (in this case your TextView) with an empty OnClickListener. Since the TextView's OnClickListener is set the OnItemClickListener will not be called.

这篇关于机器人:可点击=&QUOT;真&QUOT;意思是,这不是点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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