Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

java - android:clickable="true" mean's that it's not clickable?

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".

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...

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" />

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...