Skip to content Skip to sidebar Skip to footer

Onitemclicklistener And Onclicklistener Not Working For Listview

I have used a Custom ListView and I am displaying some data using the same ListView. When I click on the List View item, the onClickListener is not getting called. I am not able

Solution 1:

The following will do the job in your case.

ListViewpropertylistview= (ListView) findViewById(R.id.listview); 
    propertylistview.setOnItemClickListener(  myListViewClicked ):

        OnItemClickListenermyListViewClicked=newOnItemClickListener() {

            @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(YourActivity.this, "Clicked at positon = " + position, Toast.LENGTH_SHORT).show();

            }
        };

Dont forget to remove the following from the CustomAdapter

  convertView.setOnClickListener(newOnClickListener() {

    @OverridepublicvoidonClick(View v) {

         Toast.makeText(parent.getContext(), "view clicked: " + ListArray.getName(), Toast.LENGTH_SHORT).show();
    }
});

Solution 2:

If the touch events are getting intercepted inside the cell layout, in the layout for your custom cell, set android:descendantFocusability="blocksDescendants" on the top level layout of your cell. For me, it was too much of a pain to add xml attributes to every individual view.

Note that this can also be set in code:

cell.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);

I also tried this with a ListView inside a cell, and I had to override onTouchEvent to get it to work:

publicclassNoTouchListViewextendsListView {

    @OverridepublicbooleanonTouchEvent(MotionEvent ev) {
        returnfalse;
    }
}

Solution 3:

the simple code that solved my problem, and method view.setOnClickListener be within my custom adapter

    view.setFocusable(false)

Solution 4:

Check your list row layout once :

layout or any view should not be `android:clickable="true" and android:focusable="true"

if it is there just delete and run the application again.

Solution 5:

Even I was having the same problem, I am having checkbox, did the following to masker itemClickListener work,

Added the following properties to the checkbox,

android:focusable="false"android:focusableInTouchMode="false"android:clickable="false"

and ItemClickListner started working.

For detailed example you can go through the link,

http://knowledge-cess.com/android-itemclicklistner-with-checkbox-or-radiobutton/

Hope it helps Cheers!!

Post a Comment for "Onitemclicklistener And Onclicklistener Not Working For Listview"