Hi onListItemClick for listview is not working. Here i am fetching datas from SQLite using AsyncTask and displaying it in a list view. And i wants to do some actions when a list in a listview has clicked. But the click is not happening. I had tried a lot for this. Please help me.
Here is my code
And Layout code is materiallist.xml
And listso3.xml is
Add below code to your
TextView in the XML
and try again.
Another simple solution: add
android:descendantFocusability="blocksDescendants" to the root viewgroup.
You should add
android:focusable="false" for ListView row items to make ListView Clikable. Because the views in the row of ListView gain the focus so ListView is not focusable. So, in your case you can add
android:focusable="false" to the TextViews of your ListView row.
I had the same symptoms, and it drove me crazy for a while. Adding
android:focusable="false" for the list items as suggested above fixed the problem for me.
But the real issue was that I had set
android:textIsSelectable="true" for my list items (in response to a Warning generated by Eclipse); setting
android:textIsSelectable="false" fixed the problem for me, and I did not need the
android:focusable="false" option at all.
The workaround I found avoid the
ListView, but exploit the Adapter constructor that takes a
Context as parameter:
ActivityName.this is possible to cast the
Context in the adapter’s class as
ActivityName in a safe way and use its methods working like callbacks:
Given that the
getView() method of the Adapter class has a
position parameter, is possible to pass this value to the
activityMethod(int position) in order to know which list item has been pressed into the Activity where the
if you have many child-control,and its to trouble to add
android:focusable="false" to every child-control,you can add
android:descendantFocusability="blocksDescendants" to its parent-control.try it.
I struggled with this for a while – none of the provided solutions worked for me. In the end I found that having a call to
getListView() in my
onViewCreated() method did the trick, although I have no idea why. This is for a Fragment rather than an Activity; not sure if this makes any difference.
I was also struggling with this issue and none of the suggested solutions worked. My problem was that I did an override for
onViewCreated but didn’t call
super.onViewCreated(view, savedInstanceState);. Hopefully this will help someone else so they don’t spend hours trying to figure out what’s going on.
I struggled as I by mistake put android:inputType=”textCapWords” with the textbox after removing it it is fixed
Only the line below worked for me:
The whole list_view_item.xml:
The above is to be used in getView like: