Whenever I am setting OnClickListener for TouchListView then DropListener and DragListener are not working.
I downloaded the demo of the CWAC: TouchListView.
So how should I implement the OnClickListener for the TouchListView.
Please Help.
Thanks.
As i Understand there are 2 ways to solve this problem:
1. You must make only one small area off each item touchable to drag. And user will drag your items if he touch item in this area. You can implement it using x-coordinates of your item.
2. You can implement special mode of work of your listview. You can switch to this mode through menu (or another way) and in this mode all area off item can be touchable to drag but not clickable. After draging you can switch back to usual mode of listview.
PS: I describe my approach to solving the problem. It will be great to see something else.
I have just had the same problem.
If you follow the Demo project you can set your OnClickListener on the label in the IconicAdapter. The user can scroll using the ImageView and they can press the label to do whatever you would like them to do.
This solution worked for me.
Related
Good evening everyone,
I've been struggling to find out a way to do this. I have an activity. In this activity I have a "top menu", and a fragment holding a listview. The goal is for the top menu to be expanded either when the setting button is pressed, or the down arrow is swiped:
Currently, I'm just adjusting the height and properties of the top menu view according to if it's expanded or not. I'm pretty sure this is not the proper way to implement this. Thanks in advance!
I have faced similar problem with swiping elements. You can use OnTouchListener and GestureDetector to detect dragging
I wrote simple android library for this problem, it has also functions to expand view on your setting button press.
swiping library
I'm having some problems to navigate on a gridView using the keyboard (with up, down, left and right keys).
I'm new in Android and maybe this question has a simple answer. I looked for a solution and anything could help me.
The problem is that I would like to change the way of navigation among items of a grid view. I would like to do it due to two reasons.
The first reason is related to the fact that some itens have clickable subitens (and consequently the entire item is not clickable). When the focus is changed from a item i to the item i+1, for example, the item i+1 must be checked if has subitens. If yes, the focus is changed to one of the subitens depending on direction (ie. if left to right, the first subitem on the left is focused).
The second reason is that in my application, the up arrow should works in the same way as the left arrow and the down arrow in the same way of the right arrow. So, I just need see if the keyCode of a onKey event is UP or DOWN and convert it to LEFT and RIGHT, respectively.
I thought that would be a simple task: override the onKeyDown method and treat these specificities, but I observed that my implementation of onKeyDown was invoked just in two cases: (1) when other keys are pressed (with exception of the aforementioned arrows and (2) when the grid view lost the focus. For example, if the item C1 is the current item selected and the user click to the left or down, the onKey is not invoked. Otherwise, if the right or up are typed, my method is invoked.
Is there any way to cancel this internal mechanism of grid view? I tried different ways, as follows:
(1) Implementation of OnKeyListener directly on the gridview and on the item (on the adapter) as well.
(2) Implementation of different callbacks to see which one would be called before this internal mechanism (like OnFocusChangeListener, OnKeyListener, OnItemSelectedListener). I tried both for the grid view and each item on the adapter.
(3) Instantiation of the gridview with the selector setted to a transparent image. When the desired item is reached on my keyEvent, I added a visible selector. It worked on the first event but when the visible selector is setted it does not back to the invisible selector.
I tried to be clear and I hope to anyone of you could help =)
Thank you so much
How are you?
You could try use onKeyUp instead of onKeyDown, see the answer below:
https://stackoverflow.com/a/20171618/1408986
And Android documentation:
http://developer.android.com/training/keyboard-input/commands.html
Hope this help.. bye!
I solved this problem by implementing both listeners: onKey and OnItemSelected. The focus was everytime running of the grid used and jusing those listeners solved my problem. Thanks a lot.
I was trying to implement a drag down listener on my android app, and make a layout which is in view.GONE state animate and increase upto certain height as I drag down.
I tried using OnTouchListener Action Down and Action Up but it is not helping me.
How to achieve this?
Layout1(App_Header)
Layout2(MapView)
Layout3(ViewPager)
Layout 2 is hidden(View.GONE) after pressing a button.
now by dragging down the screen from the header I should get back my Layout2(MapView) increasing its height as I drag down.
I also tried using DragListener to PagerTabStrip on Layout 3, but it didn't work.
Are there any one who can help me on this?
The best way to achieve it is using OnTouchListener and a custom OnDragListener.
Here is a great example and here is another one (from google documentation)
If you need any additional help just ask!
I have a ListActivity as my main activity. I want to be able to do a few things on a single item in the list i.e.
Longpress to bring up a contextmenu for that item
Swipe left to right to slide a new screen from the right to edit the list item.
Does anyone have any code they can show me that does this?
Longpress to bring up a contextmenu for that item
See here for how to use context menus. Here is a sample project that demonstrates their use.
Swipe left to right to slide a new screen from the right to edit the list item.
See here for how to use gesture libraries. Here is a ViewSwiper that adds gestures to a ViewFlipper. Here is an implementation of a drag-and-drop ListView, based on some poorly-understood code culled from Android itself. Blending all of that together, you may be able to implement what you seek. However, this will be rather difficult, and may not result in a user interface that is very usable. I strongly encourage you to simply have list item clicks be the way to indicate to edit an item, not a gesture.
I think You can use a 2 Child ViewFlipper as your Listitem.
one child for a normal dispaly(a TextView maybe), another a EditText.
and in case it work as you said, don't forget to set gesterListener on your ViewFlipper,do showNext or showPrevious in your OnFling method.
I've been trawling the internet looking for an answer for several hours, but I can't seem to find anyone who has been able to solve this.
I've got a listview which uses a custom adapter. A row looks like this
The list is filled by an array. Everything works great.
Now, I want the ImageView and the ToggleButton to react to clicks, so I implement the OnClickListener in my adapter, put the items position in each view's tag, and then I set their onclicklistener to this.
Works great, except now I can't use the onListItemClick for starting an activity for the item! OK, I say, I just make the relativelayout holding the text in the middle there use the same onclicklistener. Works great. Everything is clickable, and life is good.
EXCEPT! Now, when I scroll the list, I cannot "continue" the scroll by just flinging again. This causes the scrolling to stop, and I have to fling once more to get it going again. It seems the onclick-thingy causes the fling-motion to be interpreted as a tap or something (it does not trigger the logic within onClick).
I know that this is possible by just going to the phone list on my HTC Hero, which has exactly the kind of layout and behaviour I want from my app. This app even seems to have the onItemClickListener working.
So how can I make sure the list keeps scrolling, and still be able to click the togglebutton, listitem and the imageview? I've been stuck on this all day, and it's giving me a headache :(
Another quick search before I go home, and I came across this:
How to fire onListItemClick in Listactivity with buttons in list?
CodeFusionMobile mentions setting the android:descendantFocusability property of the list layout to "blocksDescendants", and so I tried doing that. Everything works as expected now. Scrolling works, onListitemClicked works, clicking the ToggleButton works, clicking the ImageView works.
Just to make it clear... In the parent RelativeLayout, right at the top of the row.xml, I added
android:descendantFocusability="blocksDescendants"