CheckBoxes inside a GridView stop responding after soft-keyboard - android

I use a grid view that gathers several check boxes. The grid view is populated using an adapter that is derived from BaseAdapted. Above the grid there is an EditText.
The check boxes function ok in the beginning. But after showing the soft keyboard (by tapping the EditText, then dismissing the keyboard, even without pressing any key) some of the check boxes that were covered by the keyboard stop responding.
Any idea how to solve this?
Thank you very much!

After many trials I gave up the GridView and used instead a TableLayout, creating the TableRows dynamically. No softkeys problem with this solution, it looks exactly the same and behaves the same as a GridView (except for the entire check boxes set is loaded into memory, which might not be the case with a GridView, but still all check boxes were displayed on the activity at once so I don't think there was any memory consumption difference).
In short, TableLayout/TableRow instead of GridView for this purpose looks the same, and even easier to code, since I filled up the TableLayout directly, within a few lines of code, where the GridView required an adapter. Problemo solved, case closed. :-)

Related

Alternative to ListView that avoids EditText focus issues?

Situation
Need to present text files as a list of editable sentences or phrases as shown in the example below, for the purpose of a speech therapy tool. This was relatively easy.
The colored flags can be added, removed, or dragged to new positions as needed, and can be set to snap-to-character or snap-to-word (they will also eventually display data).
This was achieved by sub-classing EditText, to take advantage of all the in-built features like word-wrapping, spell-checking, text-selection etc.
Problem
The number of phrases or sentences in a document can be large, so using a simple LinearLayout in a ScrollView to display them is no good in this case.
To efficiently display my FlaggedEditText widgets the solution needs to take advantage of view recycling, so ListView is an obvious consideration. But as shown by the number of S.O. questions out there, ListView and EditText don't play nice together.
The requirements of the list are that:
FlaggedEditText widgets get focused when touched (the item containing the FlaggedEditText also gets selected).
Notification when an item in the list has been edited (including which item).
Standard gestures such as fling.
I've tried out numerous approaches suggested in the many S.O. questions over the past few days, to try and bend ListView to my requirements, but all seem to have their own short comings and result in hacky, messy code.
Questions
Does anyone know of any existing alternatives to the standard Android ListView out there, that are more EditText friendly?
Alternatively, does anyone have a clean, efficient, definitive approach to getting EditText working as desired in the standard ListView?
Finally, I'm considering sub-classing AdapterView to make my own FlaggedEditText specific ListView alternative. But if the issues stem from AdapterView of which ListView is also an indirect subclass, then I'd be wasting my time. Has anyone already been down this path?
Edit
Jim's excellent response below, and a recent viewing of Romain Guy and Adam Powell's old Google I/O 2010 presentation The world of ListView have suggested a possible solution.
In the I/O talk I was reminded that they convert views to bitmaps for some of their optimizations. Since only one EditText at a time can ever be focused for editing, I'm thinking I can sub-class ListView to provide an interface which, if ChoiceMode is single, will give the Rect of the selected Item and bitmaps of the ListView regions above and below the selected item. This could then be used to temporarily overlay the ListView with a vertical LinearLayout containing the "above" bitmap, an active FlaggedEditText and the "below" bitmap.
In this way, the FlaggedEditText widgets can effectively act as non-focusable EditText's in the ListView, but when an Item is selected, interaction is with the temporary overlay.
The "above" and "below" bitmaps could also easily be tinted to suggest inactivity.
Additional
In fact, I've just realized I probably don't even need the Rect of the selected Item from the interface. The "above" and "below" bitmaps and a FlaggedEditText using the same LayoutParams as per the ListView should be enough.
Many of the answers out there do not seem to describe the core issues surrounding this "problem" and why it is not "solved." The "problem" you face is that an EditText can expand and/or scroll, along with your ListView. Also, the expanding soft keyboard forces the ListView to redraw causing problems with keeping track of the focused item. And when an item is focused and has dynamic content, UX confusion can occur with touch gestures (e.g. if you touch an item in an EditText like the cursor and then swipe, did you want the cursor to move? Or the entire list?) It can lead to a lot of user frustration.
I'm sure you've seen this post:
Issues focusing EditTexts in a ListView (Android)
This creates problems in correctly displaying the elements within the ListView, problems with recycling properly (the redraw) and problems with gaining focus correctly. It is possible that creating a custom class that extends AdapterView will work, but it will probably still feel like a hack, and probably will not work as you want it to or it will be a large effort.
You will need to do a lot of backend measuring of the fonts, images and "visible" (or partially visible) items in the custom object that also account for the keyboard animation and dual scrolling (the ListView can scroll and so can the EditText - or the EditText will change in size, forcing the parent custom AdapterView to determine if it should also scroll and whether views have become visible or invisible as a result of adding or removing text/images from the focused object).
If you make assumptions like "the EditText will never be larger than X height" then you may get it to work, but obviously that is a very customized solution, which is why it is not easily implemented and isn't supported generically.
Also, you will need to make UX decisions about how to handle a focused item that has scrolled off the screen (you can track it easily, but if it scrolls back onto the screen, but it can interrupt user expectations about how swipe and touch gestures are handled - for example, does the cursor in the EditText move or does the entire list? if an image is touched, does a swipe move the image or does it scroll the list? You can assume it is not focused, but then a "redraw" event can make it lose focus unexpectedly, like the current ListView implementation.) In other words, you are likely to end up with many unanticipated odd UX issues...
Your best solution will probably be to use a dialog pop-up as mentioned in the post I referenced above. Or, when an item is tapped to be edited, you could have a layout appear above or below the ListView. You may possibly get the ListView to scroll and lock to it - to have it appear as if it were in the ListView - but again, that would be hard with the soft keyboard changing the usable portion of the screen - you can expect "drag" or a slow feel to the "snap" effect. And you will need a "done" button...
To get your custom EditText to work with this suggestion, in the ListView you could disable it and make it non-focusable, then place an empty layout over the entire EditText that captures and processes the touch/fling/swipe events. This "invisible" layout may be the only option you really have.
In other words, you should probably plan to change your UI/UX rather than try to force Android to figure out how to handle several dynamic, and possibly conflicting or unpredictable, aspects of the UX interaction of these layouts.

Scrolling of list below another view

I have seen an app which has different type of scrolling. I hope images attached will be able to explain it. Here the list when scrolled up, moves up by taking DownloadAll, Playall button up too. Later on DownloadAll and PlayAll button stops going up and only the list scrolls up.
I don't know what this is called as. I tried searching, but could not find anything similar.
How can I achieve this type of scrolling?
Take a look at "Libraries for developers" it has a section of listview where you can find different styles of listviews (plus scrolling animations such as sticky, animated scrollview, flabby etc...)

Replacing views dynamically without changing activity

I would like to know how to go about doing this small problem that I am encountering while making a video player app.
On clicking the first control(the rectangular icon) in the above image the following view must be displayed instead of it which I am quite unsure as to how to do it. Here is what it is replaced by
Also please note, by any chance the activity should not be changed. I have been able to design the views individually but having problem changing them at runtime when user clicks. Could someone go about explaining as to how it can be done or provide some suitable links to achieve my goal. Thanks.
For something as simple as this you can just change the visibility of the views.
view.setVisibility(View.INVISIBLE)
Or the more effective:
view.setVisibility(View.GONE)
Do that on the views you want gone, I suggest a wrapper class. It's either this or changing the contentView as describded below.
this.setContentView(R.layout.newLayoutToUse);
However, I have a feeling there is a better way to do what you want. It's overkill to load a complete new layout if you just want to change the image of some buttons or imageviews.
This might be a stupid solution, 'cause i'm terribly tired right now, but why not use the bringToFront() method on the View that you want to display in the front? Display them both in front of each other, maybe in a RelativeLayout, and then swap between them as you wish.
They are small objects, so don't consume memory. I don't see why this shouldn't work.
OR
Place them above one another, so they overlap and then make the above view visible/invisible depending on which one you need to display.
OR
just remembered I read somewhere that you can scroll through a ScrollView automatically from code. So display both Views in a ScrollView in succession and when pressing the button or whatever, you scroll down to make the next menu visible. When pres back, you scroll up to make the previous thing available. Should work, and might also make a nice animation between changing of the menus.

Changing UI elements while scrolling

I have a Layout with a ToggleButton and a gallery.
I'd like to change the toggleButton when I'm scrolling, I've implemented OnItemeSelectedListener and depending of the object I'm setting the button checked or not.
The thing is that the scroll freezes when the ToggleButton is changing, I know that there is only one thread for the UI but could I improve it?
I've seen apps like the CNN one which changes items like a textView color while scrolling, so should be a way...
The problem was the ToggleButton, I can change drawables, textviews and other items whitout problems but it seems that ToggleButton.setChecked is a slow code.
Finally I have two ToggleButtons overlapped, one to on and the other one to off and I make the top one visible or invisible.. apparently it's the same and it faster now :).

Android ListView with clickable items in it's rows causes problems continuing scrolling

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"

Categories

Resources