I've got a ListView that works just great, except for this minor annoyance. I can use the trackball/dpad to move up and down my list, and the background changes according to which row has focus. But when I touch the row (click or long click), there's no background change letting me know what's been focused. I've tried setting 'focusable' and 'focusable in touch mode' to true on the rows, but it still doesn't work.
Just in case it matters somehow:
I am setting onClickListeners for
each row.
The row is comprised of
LinearLayouts, TextViews, and a
single ImageView.
Focusable/clickable is 'true' for each row. Have not specified values for these on the ListView.
Trackable does act funny. I can only move between rows after touching inside the ListView. If I scroll trackball above the first item, it's impossible for me to scroll back into the list.
Any thoughts?
I can use the trackball/dpad to move
up and down my list, and the
background changes according to which
row has focus.
No, it doesn't. The background changes according to which row is selected. Selection and focus are not quite the same thing.
But when I touch the row (click or
long click), there's no background
change letting me know what's been
focused.
"In touch mode, there is no focus and no selection."
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 need a component that works like the picture below but I'm having trouble coming up with some kind of decent solution that works.
I want the list to have a center locked selection but being scrollable with the d-pad. This is for an application running on a TV so no need for touch scroll. So when pressing down on the remote d-pad the list will scroll and a new item will size up and the current selected one will size down and the new selection will still be in the middle.
I've tried doing this using a ListView that I extended and programmatically scrolling when pressing down or up. On scroll finished I called notifyDatasetChanged() on the ListView for re-inflating of the childs and in the ListViews adapters getView() I made the animation of the view located at the current selected position.
This is not optimal since I need to call notifyDatasetChanged(), which re-inflates all visible views, for the animation to apply. The UI becomes laggy when doing this and scrolling fast. It's also not possible to make som kind of compress animation when current selected item goes out of selection. There is also some trouble with the end items (read views) such the first or last in the list when doing animation of them, the may sometimes go out of screen.
I think that his must have been done before and maybe I'm missing it when searching for an answer.
Have anyone done something similar or do you have some suggestions of how this can be achieved? Maybe I'm just starting of with the wrong component here..
Regards,
Kristoffer
I'm having an issue with a listview.
It's displaying items with a checkbox on the right.
When I enables the fastscrolling, everytime I press on the checkbox, the fastscrollbar appears and it scrolls to the position I pressed rather than just checking the checkbox...
If it matters I enable the fastscrollbar dynamically depending on the number of items in the list.
How can I fix this focus issue ?
Edit: In fact I'm also having the same issue without a checkbox. When I press on the right of the listview item, it doesn't open the item like it should but it scrolls to the position I pressed. Same behavior in a GridView...
I have a listview, which is scrollable, with dynamically items loaded from the database. And I have two buttons, "UP" for scrolling up by 100 pixels and "Down" for scrolling down by 100 pixels also.
The problem is that after I click down or up, the screen scrolls but after that all items in listview are not selectable at their right place. For example, I press down key and it scrolls well but after that I click item3 and it accepts item1 as clicked object.
I have tried ListView.refreshDrawableState() but it doesn't work.
You might want to use the setSelection() method instead of scrolling the list by 100 pixels each time. Increment the selection when you're scrolling down and decrement it while scrolling up. This will assure that the right item is being clicked. Hope this helps.
I optimizing an application for use with the trackball. I have a ListView with rows that contain three buttons. Here is my problem: whenever I move the trackball to the child buttons of the row, the focus disappears from the parent container (the row). I want to keep the focus on the entire row, as well as whatever button is currently selected for the given row.
Basically, what I need is an attribute opposite to android:duplicateParentState, something called "android:duplicateChildState." Unfortunately, android:duplicateChildState does not exist.
At the moment I have hacked it in a way such that I set an onFocusChangedListener and force the parent container to also be selected with the ListView.setSelected method. This works, but unfortunately there is a flicker as this setSelected message is posted and run to the UI thread.
Does anybody know of a way that I can keep this focus on the parent, as I traverse the children widgets?