I have a Listview with inside some elements (a button and an edittext). I was able to disable the button after the first click on it. My problem is that if I scroll the list, and then return upside, my button is again enabled. While i'd like that It will not change his state if I don't change activity.
So I think that there is a kind of refresh when you scroll the list....how can I avoid this??
Please help me!!!
Example something what you want
Related
I have tried to use both ScrollView and ListView.
I figured out that if I use ListView and I click one of items let current fragment be replaced by next fragment and press back button to prev fragment. The scroll position of ListView will keep at same position. But if I use ScrollView, it will not.
I don't understand why they are different? And how can I make ScrollView keep its position after press back button?
Actually, I have searched some answer at StackOverflow. But I want to know the reasons and find an easier way to make ScrollView and ListView have same behavior.
Please help me! Thank you!
Fragments automatically save and restore the states of their Views, as long they have IDs assigned.
So if you assign an ID to your ScrollView, its scroll state can be restored:
<ScrollView android:id="#+id/scrollview"
...>
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'm having the next problem.
I have two layouts, one behind the other. When I click on the first view the "click" pass trough the view and it arrives at the second one. How can i stop the onclick only for the first view and enable it when i want at the second view?
Thanks in advance.
EDIT
A image with my problem
2EDIT
Why am i doing this? Because i put im my app a menu like facebook. So i have the menu in the red view and i animate the green to the right to see the complete menu. See http://venturebeat.com/2011/12/07/facebook-for-android-upgraded-with-better-navigation-faster-photo-views/. Seems that the solutions is with set the view clickable to false.
It's not clear what and how do you want to achieve, but it doesn't seem to be a good idea to have RelativeLayouts on top of each other. For this you could use a FrameLayout, or if your layout is a bit more complicated, you could play with setting the views unclickable.
If this doesn't help you, please post some code.
EDIT
It's still not too clear why do you want to achieve this, but you can set the second view unclickable, whenever you want.
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.
I added a ListView and a Button to a layout.
What I want to do is, when I click the button, the ListView should scroll to a specified item such as the 10th to the top. But I don't want it to scroll too fast like flipping a page.
How can I do this? Can I add a fraction to a ListView? If so, how can this be archived?
i haven't try it but you can use "setSmoothScrollingEnabled(boolean smoothScrollingEnabled)" method of listview.
i think this will help you.