how to make an imageview clickable in an listview

后端 未结 6 952
一整个雨季
一整个雨季 2020-12-18 11:44

Hi i have created a basic listview and added a textview and imageview in it.



        
6条回答
  •  余生分开走
    2020-12-18 12:29

    You have to implement your own cursor adapter, and in that you have to override the getView method and then set the onclick listener to 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) 
                {
    
                }
            });
    
    
        }
    
    }
    

提交回复
热议问题