onListItemClick no llamado en Listfragment

Hello I have a problem with the onListItemClick Method on a ListFragment.

I have an activity that holds 2 ListFragments. The first one is a sub navigation and the second one shows some content. The sub nafigation werks perfectly fine and the onListItemClick event is invoked when clicked on a list item. But for the second ListFragment, nothing happens. The method is not invoked.

So far I also tried to replace the Listfragment with a Standard Fragment and set the setOnItemClickListener manually. But it is not fired when I click on a list entry. I also tried to test it with a different Listener (e.g onLongItemClick), but nothing happened either.

These are the settings for my listview.

   <ListView    
            android:id                  ="@+id/mylistview"
            android:layout_width        ="match_parent"
            android:layout_height       ="match_parent"
            android:divider             ="@android:color/transparent"
            android:dividerHeight       ="10dp"
            android:listSelector        ="@android:color/transparent"
            android:cacheColorHint      ="@android:color/transparent"/>

Note, that i replaced the id with the standard "@android:id/list" when using a ListFragment.

Does anybody know what goes wrong here ? Can it be that the other ListFragments gets all the onListItemClick calls and prevents this one from being fired ?

Here is the adapter that is attached to the list:

setListAdapter(new CustomRatingBarListAdapter(mListEntries,
            getActivity(), R.layout.content_view_list_layout,
            new int[] { R.id.list_item_text1 }, new String[] { TEXT});

preguntado el 09 de marzo de 12 a las 14:03

revisa mi mayor post if this help you.. -

5 Respuestas

If you have an item in your layout that can steal input from other components like a RatingBar, that component needs to be defined as not focusable, so it won't grab events.

Respondido 09 ago 12, 15:08

Edit your adapter's list items (rows) (the *.xml file on layout/ folder) setting:

android:focusable="false"

Or if you are injecting them programmatically, code:

yourChildView.setFocusable(false);

Do this with all the UI components that could take focus such as Button, RatingBar, EditText, ToggleButton inside the View that constitutes the list item (row) etc.

respondido 09 nov., 12:01

In my concrete situation it hasn't helped to only set the android:focusable atributo en mi myRowLayout.xml. I'd to also set it programmatically - god knows why. - Jens Kohl

Ok, I found the error. It was something complete different. In fact I had a rating bar as a list item and even tough it did not cover the whole list item it somehow got all the click events.

Changing the visibility to GONE for now solved the problem. So the problem was here the layout of a single list item and not the adapter.

respondido 10 mar '12, 14:03

Utilizan OnTouchListener() instead to other components in my list row did the trick for me. Hope that help.

contestado el 31 de mayo de 13 a las 23:05

I think you can get your ListView by calling this method getActivity().

If I am right then use this getListView(); insted de getActivity().

respondido 03 nov., 13:12

Since 2 ListFragments are active at the same time maybe it has something to do with the context. But changing the context to getListView() does not help. Since both Fragments are attached to the same activity, do I have to tell the activity how to handle the clicks ? - Normando

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.