Clicking a ListView that has a longclick item on it - android

I have studied a number of answers to similar questions but none work in this particular instance (which isn't covered anywhere else).
I have a ListView containing ListItems with a number of TextViews on each.
When I do a short click on any ListItem I am expanding that item to show more information (by implementing an AdapterView.OnItemClickListener).
One of the TextViews has android:longClickable="true" set. This is so that I can run another action when that particular TextView is long clicked (I achieved this by implementing AdapterView.OnItemLongClickListener and checking for the particular TextView id)
I have set android:clickable="false" for that TextView
My issue is that now when I do a short click anywhere on the ListItem the item expands as expected - EXCEPT when the short click is on that particular TextView, in which case nothing happens.
So the short click is being consumed by something even though I have set clickable to false?
Have I missed something obvious? If I set the android:longClickable="false" on that TextView then the expansion works fine again.

It seemed the event is interrupted by the long click listener.
Try to check the return value of the "onItemLongClickListener", it's a boolean type, which will decide the event is handled or not.
Good luck!

Related

Accessible way to click both ListView row and Button in row?

It's easy to make a row in a ListView do something when it is clicked. But add something else in the row--such as a Button or other control--that has an OnClickListener, and suddenly nothing happens when the row is clicked.
Before you close this question as a duplicate, I am perfectly aware that there are a number of StackOverflow questions about that. They generally either recommend setting the Button android:focusable="false" or setting android:descendantFocusability="blocksDescendants" on the ViewGroup containing the row Views.
These work, but one problem: if you're navigating with the keyboard (tabbing or arrow keys), it skips right over the Button.
Is there a way to solve the issue and allow people to "click" either row or Button without having to actually tap the touchscreen?
Setting an OnClickListener on each row (instead of setting an item click listener for the ListView) did not help.
I did find some more info, such as using ListView.setItemsCanFocus(true) Using Android, how can I select rows from a ListView which contains Button controls and using beforeDescendants Focusable EditText inside ListView but can't get both the row and the button to be usable with a keyboard.
BUT it occurred to me to try and test out Gmail with a keyboard. I can't find a way to mark a row as a favorite (select the star). So apparently even they aren't making it fully accessible! Oh well. A lose cause I suppose.

Android LongClick in a ListView of Clickable Elements

If I have a fragment containing a ListView where each row is a series of clickable elements (say, 3 buttons) filling all available space on the row, can I possibly have a long click callback for the entire row?
I want the user to be able to click on any of the three elements with a quick click but the long click should select the entire row/entry.
I have tried hooking up the ListView with the setOnItemLongClickListener while setting android:longClickable on the individual elements in the layout, but I never see the callback get hit for the long press.
Is this feasible? Do I need to have each element listen for the long click and push it back to the ListView somehow?
Since these three elements(Button) filling up entire space of the , it is difficult to set long click listener for that row...
so good idea is set one same long click listener for these elements rather than row, if they don't have any long click events..
thank you
Put longclicklistener on list view and when that is performed some boolean make true and in your 3elements clicklisteners check if it is false than do other commands.

ListView row with EditText, clickability, and context menu -- how to put it together?

I have a ListActivity-based activity that uses a context menu for the items. After adding an EditText to the row of a ListView, the context menu stopped working, and also the item does not react on a click. It seems that it is blocked somehow by the focus of the EditText. I can enter the EditText value, but I cannot get the earlier context menu, and I cannot start another activity via clicking the item.
I have possibly found the related comment that says:
Android doesn't allow to select list items that have focusable elements (buttons). Modify the button's xml attribute to:
android:focusable="false"
It should still be clickable, just won't gain focus...
... so I did the same for the EditText (I am not sure if the button case can be generalized for the EditText). Anyway, the item is clickable again, the context menu appears... However, the EditText part of the text stopped working now. (Actually, I did not implement the reaction to the EditText -- the keyboard simply does not appear.)
Is it possible to have the clickability of the list item and also make the EditText work the expected way?
I don't know if this would help you but it is a post I've found when I was trying to use a ListView with buttons inside.
ListView Tips & Tricks #4: Add Several Clickable Areas
Hope this helps.

Android Spinner does not close after using setSelection()

I have a scenario where I want to programmatically change the value of my spinner using setSelection(). This works great, except that if the spinner is open (expanded?) an the time, the spinner does not close. Eg, the menu stays up, despite calling setSelection().
How can I programmatically close the spinner? I have tried performClick() to no avail.
edit: more details:
The reason I'm trying to do this is that my spinner actually uses a compound layout for each selection row. Namely, I have a linearlayout which contains an image, text, and button. The idea was that the button serves as an "edit" button (which opens an activity), while pressing on the image/text select the row (per usual).
The problem came when I added the button. Suddenly, the image & text no longer captured the press event to change the combo. In other words, adding a button to the row destroyed the touch-handling capacity of the entire row. So I tried to manually implement a click handler for the image/text, which subsequently executed a setSelection... which is where I ran into this problem.
You say that after adding the button you lost the click handle on the entire row. Try adding this android:descendantFocusability="blocksDescendants" to your row layout, and see if you can get the clicks to work properly.

On Android, click to expand list -and- click on a button?

I have just started my career as an android programmer, and am currently relying heavily on the sample code and api examples. I have been working with this api example, to produce an expandable list of items (note this example does not use the ExpadableListView).
In playing with the example, I tried to add another widget that would become visible and be gone at the same time as the text (mDialogue in the sample code). This works well with another TextView, but as soon as I tried to add a button widget, it stopped working. The list would expand on first click, showing my hidden TextView and Button, but it will not disappear on further clicks. The button is however, clickable, and I was able to set up an onClick listener to change the button text back and forth.
I'm starting to wonder, is it just not possible to have a clickable item inside a clickable list item? Or is there some kind of work around? Would it solve my problem if I used ExpandableListView?
You have two options of how to handle focus within a ListView controlled by ListView#setItemsCanFocus(boolean). If you want individual Views within a list item to focus so that the user can interact with them individually instead of with the list item as a whole, call it passing true. false is the default behavior.
The default behavior where ListView manages item focus and clicks is basically a shortcut/optimization for the common case where the whole item acts as a single unit from an interaction standpoint, but its layout may be complex. When you tell ListView that its items can focus it disables this special behavior and you should use the more traditional mechanisms of handling events on the Views within the list items. (Listeners, overridden on* methods, etc.)
But why do your list items stop taking clicks when your ListView isn't set up for focusable items? ListView will only generate item click events if the list item view returns false from View#hasFocusable(). This means no children of the list item can be focusable if you want to receive item click events for it. As soon as your button becomes visible, the list item has a focusable child and will no longer receive list item click events.

Categories

Resources