From readings, I have the height of the soft keyboard with the onSizeChanged method. What I want to do is to display a list in place of the soft keyboard when it is closed, and remove the list when the keyboard is required again.
The way I'm doing it at the moment is that when a button is pressed, a list will be made visible and the keyboard dismissed using the InputMethodManager. The problem in the button's onClick method, I set the list to be visible, but the keyboard hiding animation is still ongoing. This causes a visible flicker to happen, since the set visible call triggers the layout to be redone, and the list becomes visible while the keyboard is still there, pushing other views out of sight to the top. After the keyboard animation is finished, other views become visible again, this process causes a visible flicker...
Anyone got any suggestions on how I should approach this??
Pulling my hair at the moment, since setting the list visible during onLayout or onSizeChanged doesn't let the list become visible...
Thanks!!!
Dave.
you can implement onConfigurationChanged(Configuration) method in your activity. Also, to get this method called you should add information in your manifest file to specify in what situations the method should be called like that:
android:configChanges="keyboardHidden|orientation"
Look here for additional details.
Related
I've design the user interface of my app as a collection of views, not activities or fragments. I manage the showing and hiding of views on this collection of views which are right on top of each other.
I believe I chose the wrong design principle to use for my app. The problem I am having is that when I hide a view in order to show another one; the button that resides on the hidden view fires its on-Click listener.
After reading some of the Android Reference documentation, I see that the view tree will navigate down the hierarchy of views in order to consume the touch event. It is then that the on-Click listener of this button is called.
What I need is something to prevent the button from the hidden view to stop calling itself when the user touches the shown view. I know that calling setVisibility(View.INVISIBLE) stops the on-Click listener from being called.
I was thinking of the ViewTreeObserver class that will allow me to create a listener of view hierarchy that somehow allows me to get a handle of all the hidden views in order to call setVisibility(View.INVISIBLE) on the hidden views.
Any ideas or advice
When you do setVisibility(View.INVISIBLE) for a view, it will still present in the layout. So instead of setVisibility(View.INVISIBLE), try setVisibility(View.GONE).
This will remove the view completely from the layout including the onClickListner attached to it.
When you want that view back, you can use setVisibility(View.VISIBLE) to get it back.
I'm trying to find a way to lock the user inside a ListView (When using the D-Pad) preventing it from losing focus, allowing the user to navigate only through the ListView until "exit" is explicitly called.
There's any easy way to do this?
Found!
If you need this, it will be enough to set those parameters in xml:
android:id="#+id/myListView"
android:nextFocusDown="#id/myListView"
android:nextFocusForward="#id/myListView"
android:nextFocusLeft="#id/myListView"
android:nextFocusRight="#id/myListView"
android:nextFocusUp="#id/myListView"
Of course myListView is just an example id, and you could use this technique with any kind of View, it locks the focus setting the next focus to itself, in any direction.
The user is then locked inside that view until the view disappears or the focus is programmatically moved to another view.
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.
This has been bugging me for a few days now. I have a FrameLayout and one of the elements within the layout moves to reveal a menu. I can paste the code if requested, it's a bit long since it's my play code and I haven't used any styles. I digress...
When the user presses a particular button it calls a startAnimation on a custom LinearLayout which is layered on top of another stock LinearLayout. Pushing the button again will put the custom LinearLayout back to it's original location, thus hiding the menu.
I had to create a custom LinearLayout to override onAnimationEnd so the layout would stop and stay at the final animated position (I found this based on some other questions asked here on StackOverflow).
The problem arises when the user actually presses one of the visible menu items. One of the items, for example, sorts or reverse sorts the displayed list. It appears that right after I call notifyDataSetChanged on my BasicAdapter the screen redraws itself and my menu is hidden. I have no code that closes the menu, it's almost like the entire Activity is re-created or reset when the list is told to redraw.
I should also point out that I'm extending an Activity not a ListActivity. I'm targeting API 10 (Gingerbread, 2.3) and up.
If any one has any pointers, I would greatly appreciate it. I've been wracking my brain on this for days now and it's driving me crazy. Please let me know if I can provide any more info.
EDIT:
Here's the SO post about overriding the onAnimationEnd method.
Android TranslateAnimation resets after animation
Do you record which item's menu has been opened yourself? If not, then it means that you let the UI system do the remembering for you, which would mean that this information would be lost or rendered useless (since you have changed the item ordering), so all the items reverts to their initial states.
The solution is to associate the menu opened/closed state with each data in the list, then when the adapter's getView method is called, you can rebuild the correct UI state.
I have a problem updating android listview items cell.
The listview_item.xml is an ordinary listview item except that it has a hidden panel at the bottom. So the last part of listview_item.xml is LinearLayout that has another button inside it. This whole layout is set to gone until user clicks on a visible button in the list item. This sets the hidden LinearLayout to visible and it displays. So far so good. Now the hidden LinearLayout is open, and showing and I want to close it. So I click on a button that is inside this previously hidden linear layout and set the visibility to GONE which was its previous state. The result is nothing happens right away. The panel remains open until I scroll it out of site and back again. Then it does not show again. I'm sorry I don't have the code to post but thats the whole situation. I just cannot get a list item to refresh on the spot. Opening using a visible button works fine. But closing the same panel from a button within the panel seems to do nothing. I have tried running dataSetChanged() etc from inside the adapter but only scrolling out and into view will close the panel. Does anyone know why closing is different from opening? Why I get an immediate reaction to setting gone to visible but not the other way. The only difference it seems is that I am firing the event from a button on the previously hidden panel. Sorry its wordy, but don't have the code in front of me at the moment.
I think nobody here can help you without a code. notifyDataSetChaged() is the method that must help you, but if it is not - it obvious that you do something wrong. You must save visibility state of element of each list item in associated with this list item object (or model whatever). Check your code one more time and debug it.