I have a ListView that lives on top of another view.
The very first cell of the ListView is transparent so that you can see the view behind it and then scroll the rest of the contents over it.
I would like the background view to capture touch events only when the transparent cell is on top of it. Is this possible? I tried a million different approaches with overriding dispatch touch event in the first cell or on the listview but haven't had any success.
When you intercept dispatchTouchEvent, check your ListView, find the top cell (the transparent one), and if the x,y coordinates of the MotionEvent are within that cell, return false. Otherwise return true and your ListView will get the events.
you can also set a tag for the transparent cell and you can get it in onclick() item. you can do anything once you have determine the cell.
Related
I have a Listview in a Fragment, and when I click an item a new Fragment is shown.
The problem is that for few milliseconds i can see the item selected by the touch. Is there a way to make these Listview programmatically selectable only? For example when I return to the Fragment and something connected is running (i already know how to select an item in Java, i just need to know how to disable touch clicks).
The item is colored with a selector and the Listviews are set to choice mode single.
One way to do it would be to implement the ontouchListener() of the fragment, and rewrite the onTouch() method with a simple:
return false
to consume the event.
You can achieve this quite easily. The two ways that are on top of my head are :
Disable touch on the list.
Put your ListView in a RelativeLayout (rootLayout) in the RelativeLayout(rootLayout) first item should be your ListView and the second can be another RelativeLayout(coverLyt) with height and width set as match_parent and clickable set to true. This will make the coverLyt take the touch events instead of your ListView. When you want the listView touch events to work set coverLyt's visibility to gone and visible when vice versa.
I created a drag and drop gridview (using an OnDragListener). Grid items can be dropped upon one another. However, I also want to be able to re-order them. I implemented this, but there is a major issue left standing: the user control part.
When I drag around my shadow object I want the items to make space for my dragged object while I am dragging it around. I already implemented the moving of the other items, but I cannot seem to figure out a way to find out IF/WHEN I am in between two items. I get drag events when I hoover ABOVE an item, but not in between then. The gridview does not get any onTouchEvent calls when I am dragging, not even onInterceptTouchEvent calls.
Does anyone know a way in which I can implement this?
I already tried:
Implementing onTouchEvent and onInterceptTouchEvent in the gridview. Problem:
The gridview does not get any onTouchEvent calls when I am dragging an item, not even onInterceptTouchEvent calls.
Setting another draglistener on the whole gridview. Problem: ACTION_DRAG_LOCATION gets only called a few times, not on every move (location change), as is documented (!!).
I removed the padding between the grid items and gave the items themselfes some extra size, so that you are never inbetween items, but also on the side of one of the items. I detect when I'm at the side of an item and move the items accordingly to make space for my dragged item.
I have a Gallery based View with a negative spacing between elements, so that one zoomed out behind the previous, i.e. 'carousel'. Zooming and carousel effect is achieved by Camera transformation.
The problem arises when I try to click right side of foreground item and what I really get is click on item behind it (always to right of it)
Let me enumerate what I've already tried:
setChildrenDrawingOrderEnabled(true);
z coordinate of background item is obviously greater then foreground
one
getChildDrawingOrder was overridden as many ways as possible (and I
found out that it doesn't play any role at all - touch events don't
depend on visibility order of views)
Seems like next(right) child has greater index and therefore a priority of handling UI events, and my z-coordinate/drawing order manipulations don't change anything.
So question: how to make foreground item responsible for all click events on it?
I have a viewgroup with textviews that are added dynamically into the viewgroup. How would I add the ability to drag and drop a textview between other textviews.
Is there a way to detect what view you have dropped it over.
If it makes it easier the textviews could be buttons.
On API 11 and up, you can use the built in functionality:
https://developer.android.com/guide/topics/ui/drag-drop.html
On previous versions, you can also do it by hand:
In theory, you have to add an onTouchListener for your views, which on action down saves the touch position relative to the view position.
Then, on receiving a touch move event, you set the position of the view to reflect that.
On receiving up event, the user has dropped the view, you check the current coordinates and compare them to the other views, if it is before another view, you move that view up and set the position of the moved view to be in line with the others again.
You can limit the dragging to only x/only y by only changing those values.
I work on an application for blind people and the difficulties
I am having that, when the user swipe one finger from top screen to bottom on a listview, on which ever item finger goes on while the finger moves I want to find out the position basically details in the item.
This is not a onitemclicklistener! the finger moves on the items so the screen goes on touch mode. Is there any listener or around way of finding out the postion of the item?
your helps and comments much appreciated.
Here is a wild suggestion, not tested:
In getView() of the listview adapter, use View.setTag(Object) to attach any custom data to the view.
Set an OnTouchListener() to each view before returning.
In the OnTouchListener() onTouch(View, MotionEvent), you get the view, and you can do view.getTag() to get the custom data that you attached.