Click is not working on the Listitem Listview android

37,010

Solution 1

The first thing what you have to note here is, whenever there are Clickable elements like Buttons or ImageButtons present in your ListView element, they take the control of click events. And so your ListView won't get the chance to accept the click event.

What you simply have to do is, set the focusable attribute to false for the Button or ImageButton you have in your ListView. But still they will work without any problem and also your ListView's onListItemClick will also work.

Try this,

        <Button  android:id="@+id/textsize_increaser"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/back_button"
        android:focusable="false"
        android:text=" A + "/>

Here I have added this android:focusable="false" and it works fine. try it.

Solution 2

Have you set the choice mode of ListView to SINGLE :

     listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

And if you have any clickable imageview or textview or button in the list item, then make them not focusable (in your Adapter class):

        yourButton.setFocusable(false);
        yourButton.setFocusableInTouchMode(false);

Solution 3

Are you using custom Adapter? and inflating layout with button or any view that eats away the list list view focus as child, then it won't work obviously. make sure to set

    android:focusable="false"

to such view in xml file. hope this works for you.

Solution 4

Set this in your listactivity java file

listview1.setFocusable(false);

Solution 5

Actually there is a parameter meant for that to prevent children views from getting focus, just add the following in the parent layout:

android:descendantFocusability="blocksDescendants"

As the documentation explains:

The ViewGroup will block its descendants from receiving focus.

Share:
37,010
Rajesh Rajaram
Author by

Rajesh Rajaram

I've been programming professionally for about 3+ years. I'm specialized in Java, C# and Android also work as a Mobile Application Developer. I am passionate about writing usable and secure mobile applications and Windows application. My interest in mobile technology as made me as good application developer. I have developed nearly 18 apps on android and 3 apps in windows in my 3+ years of experiences. I also have a good working knowledge on C# and ASP.Net, WCF,XML-SOAP, JSON web services. Specialities on: Java, C#, Android.

Updated on March 09, 2020

Comments

  • Rajesh Rajaram
    Rajesh Rajaram about 4 years

    I implemented the android listview with the ListActivity. Here I have the problem that when i click on the list item no action is performed when the flash color is also not coming that is the orange color. So do you have any idea about this kindly answer to my question.

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) 
    {
        super.onListItemClick(l, v, position, id);
        Toast.makeText(getApplicationContext(), "msg msg", Toast.LENGTH_SHORT)
                .show();
    
    }
    

    I put this code also into the Main ListActivity.