-1

I have a ListView with Custom Adapter. I have seen this thread where people asked if the items in the custom view had a clickable item. And Yes, I have a clickable ImageView in the listrow. So clicking anywhere else(other than that ImageView) should perform some other action. I gave an onItemClickListener to the ListView. However, it doesn't work on first click and works on two-three clicks.

Update: In my adapter's getView method, I set onClick of ImageView like this:

holder.chatImageView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                            //Stuff here
                     }
        });

It works fine, and in my activity, I gave onItemClickListener to listView likw this:

onlineListView.setOnItemClickListener(new OnItemClickListener() {


            @Override
            public void onItemClick(AdapterView parent, View view,
                    int position, long id) {
                //Stuff here

            }
        });

PS: I didn't explicitly give any focus to anything.

Community
  • 1
  • 1
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
  • Maybe the you set a focus in the image? Post some code please – Alejandro Alcalde Jun 06 '14 at 07:49
  • I use a custom Cursor adapter and button click is well differentiated from the list row click, all is working fine! Post some code.. – Skynet Jun 06 '14 at 07:50
  • I use a custom adapter, I usually only construct my view in the getView in my adapter. I implement the onlcick listener in my frag/activity where I will use the on click.. then override the onListItemClick() method. – Social_Engineerer Jun 06 '14 at 08:20
  • have you tried use `convertView.setonclickListener` in getView method instead of `onlineListView.setOnItemClickListener`? – Shayan Pourvatan Jun 06 '14 at 08:25

1 Answers1

1

Some time ago I've faced the same problem but with a CheckBox, I've resolve it by creating a onClickListener as member of the Custom Adapter. For example

public MyAdapter extends BaseAdapter{
    // ... ..

    // ... ...

   private OnClickListener imageClickListener = new OnClickListener()
   {

       @Override
       public void onClick(View v)
       {
           /// your data .getTag()
           // process onClickListener for image
       }
   };

}

And then, in your getView:

if (convertView == null){
   //Create your views and register onClickListener
   holder.chatImageView.setOnClickListener(imageClickListener);

}

Add android:focusable="false" to your image in xml.

Hope it helps, Here you have the entire example:

Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79