Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView selector does not work

I am forming a tabhost like layout in my application with several ImageView. When I select on an item, the image will change. However, I tried to click on it, nothing happens! why???

activity_main.xml

<TableLayout 
    android:id="@+id/main_tab_bar"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:stretchColumns="0,1,2,3,4">
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView 
            android:id="@+id/news"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main_tab_news_selector"/>
        <ImageView 
            android:id="@+id/share"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main_tab_share_selector"/>
        <ImageView 
            android:id="@+id/camera"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main_tab_camera_selector"/>
        <ImageView 
            android:id="@+id/status"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main_tab_status_selector"/>
        <ImageView 
            android:id="@+id/others"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/main_tab_others_selector"/>
    </TableRow>
</TableLayout>

main_tab_news_selector.xml (the other selectors are just similar)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item 
        android:drawable="@drawable/ic_action_time"
        android:state_focused="true"
        />
    <item android:drawable="@drawable/ic_action_view_as_list" />

</selector>
like image 645
Simon Avatar asked Dec 04 '14 04:12

Simon


1 Answers

Just add this to your ImageView

android:clickable="true"  
like image 82
Maher Abuthraa Avatar answered Oct 20 '22 00:10

Maher Abuthraa