2

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?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Fcoder
  • 9,066
  • 17
  • 63
  • 100
  • How many times will this question be repeated on SO. Please search on this website, it alone has dozens of custom listview related questions –  Mar 19 '12 at 07:14

3 Answers3

3

Add an imageView.. make it clickable by adding this to your ImageView tag:

android:clickable="true"
android:focusable = "false"
Nimantha
  • 6,405
  • 6
  • 28
  • 69
ngesh
  • 13,398
  • 4
  • 44
  • 60
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(),

http://developer.android.com/reference/android/view/View.html#setOnClickListener(android.view.View.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