How to make list view images

Hi, I created a basic list and added a text view and image to it.

      

<ImageView
    android:id="@+id/icon"
    android:layout_width="50px"
    android:paddingLeft="2px"
    android:paddingRight="2px"
    android:paddingTop="2px"
    android:layout_height="wrap_content"
    android:layout_alignParentRight = "true"
    android:src="@drawable/call"
/>

I need to make a click to view images so that, if some clicks on it, the action will occur as a new action opens. Can someone help me how to do this.

thank

+3
source share
6 answers

You need to implement your own cursor adapter, and you need to override the method getView, and then install the onclicklistener on your image:

public class SMSimpleCursorAdapter extends SimpleCursorAdapter{

    Context context;
    Activity activity;
    public SMSimpleCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context=context;
        this.activity=(Activity) context;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        View view = super.getView(position, convertView, parent);
        long id=getItemId(position);
        ImageView image= (ImageView)view.findViewById(R.id.icon);
        image.setOnClickListener(new OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {

            }
        });


    }

}
+4
source

Use instead ImageButton:

<ImageButton
android:id="@+id/icon"
android:layout_width="50px"
android:paddingLeft="2px"
android:paddingRight="2px"
android:paddingTop="2px"
android:layout_height="wrap_content"
android:layout_alignParentRight = "true"
android:background="@drawable/call" />
+3
source

,

:

ImageView myImg= (ImageView) findViewById(R.id.icon);
myImg.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                //Launch Intent or whatever you want here
            }
        });
+1

To make ImageViewclickable, you can set the property android:clickable="true"in ImageView .xml

+1
source

try this for your image: it worked for me

android:focusable = "false"
0
source

it works:

    ImageView myImg= (ImageView) findViewById(R.id.icon);
    myImg.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(YourCurrentActivity.this,YourNextActivity.class);
                startActivity(i);
        }
    });
0
source

All Articles