I want to have a ListView that have an image in every item (star) and that image is clickabe. In other word user can click on star of every row of ListView and I want to define click action for that. How I can do this?
Asked
Active
Viewed 2,347 times
3 Answers
2
you can make a ImageButton like
<ImageButton
android:id="@+id/sound_button"
android:layout_x="430px"
android:layout_y="219px"
android:layout_width="48px "
android:layout_height="48px"
android:scaleType="center"
android:src="@android:drawable/volumeicon"
android:background="@drawable/clearbuttonup"
/>
and make a new xml and name it selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
OR you make a Imageview and setproperty of that ImageView isClickable="true"

Nikhil Lamba
- 593
- 1
- 6
- 17
0
You can use an ImageButton,
http://developer.android.com/reference/android/widget/ImageButton.html
You can also simply make the image clickable, and set it's onClickListener(),
The problem with this however is that there will be no visual feedback to the user as the image is clicked. An image button looks and acts like a button, and if you are willing to provide normal, pressed, etc versions of the image, you can attach a state list drawable to the image button to make it look very professional.
http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html

Nimantha
- 6,405
- 6
- 28
- 69

Jeffrey Blattman
- 22,176
- 9
- 79
- 134