3

I have a listView with several element and section header. All item have a section header but display this only if neccessary. here the xml code of may item :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector_transparent"
android:paddingLeft="@dimen/padding_small"
android:paddingRight="@dimen/padding_small" >

<TextView
    android:id="@+id/item_training_section_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/item_training_section_header_margin_top"
    android:background="@drawable/list_selector_transparent"
    android:paddingLeft="@dimen/padding_small"
    android:textColor="@color/item_training_section_header_color"
    android:textSize="@dimen/item_training_section_header_text_size"
    android:textStyle="bold"
    android:visibility="visible" />

<RelativeLayout
    android:id="@+id/item_training_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/item_training_section_header"
    android:background="@drawable/list_selector"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/item_training_logo"
        android:layout_width="@dimen/item_training_image_width"
        android:layout_height="@dimen/item_training_image_height"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_margin="@dimen/margin_small"
        android:contentDescription="@string/image_description" />

    <TextView
        android:id="@+id/item_training_title_formation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_margin="@dimen/margin_small"
        android:layout_toRightOf="@id/item_training_logo"
        android:textColor="@color/item_training_title_formation_color"
        android:textSize="@dimen/item_training_title_formation_text_size" />
</RelativeLayout>

I try several thing with "android:clickable" and "android:descendantFocusability" but nothing work. Do you have any idea ? Thank for yours responses ?

zicos22
  • 412
  • 2
  • 8

1 Answers1

5

So, I found the solution. It was very simply but I don't sure to understand why :

I just insert the clickable parameter at true my section header :

android:clickable="true"

Here the all item :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/padding_small"
android:paddingRight="@dimen/padding_small" >

<TextView
    android:id="@+id/item_training_section_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:clickable="true"
    android:layout_marginTop="@dimen/item_training_section_header_margin_top"
    android:paddingLeft="@dimen/padding_small"
    android:textColor="@color/item_training_section_header_color"
    android:textSize="@dimen/item_training_section_header_text_size"
    android:textStyle="bold"
    android:visibility="visible" />

<RelativeLayout
    android:id="@+id/item_training_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/item_training_section_header"
    android:background="@drawable/list_selector"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/item_training_logo"
        android:layout_width="@dimen/item_training_image_width"
        android:layout_height="@dimen/item_training_image_height"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_margin="@dimen/margin_small"
        android:contentDescription="@string/image_description" />

    <TextView
        android:id="@+id/item_training_title_formation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_margin="@dimen/margin_small"
        android:layout_toRightOf="@id/item_training_logo"
        android:textColor="@color/item_training_title_formation_color"
        android:textSize="@dimen/item_training_title_formation_text_size" />
</RelativeLayout>

Anybody can explain this solution ?

zicos22
  • 412
  • 2
  • 8
  • You can find your answer here : http://stackoverflow.com/questions/7894815/android-androidclickable-true-means-that-its-not-clickable/7897720#7897720 – Ali Mehrpour Oct 10 '14 at 22:42