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>
Just add this to your ImageView
android:clickable="true"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With