Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

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

like image 253
Jake Wilson Avatar asked Oct 25 '11 19:10

Jake Wilson


1 Answers

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.

like image 58
David Avatar answered Oct 25 '22 06:10

David