i have a simple list view control
my queries are:
1) how to set first row selected on start (after fill data in list view)
2) when i navigate by hardware button i got AdapterView.OnItemSelectedListener and color of row background change, but when i click i not get any OnItemSelectedListener and no row selected. How to select row on click.
3) when i change focus list row selection removed,
please any one with any solution, code example or articles
i search but no susses
with regards
Chandra Kant Singh
how to set first row selected on start
(after fill data in list view)
Call setSelection() on the ListView. However, this only will have a visual effect if the user entered your activity via the pointing device (trackball, D-pad, etc.).
How to select row on click.
You don't.
when i change focus list row selection
removed,
If I understand what you mean by "change focus", this is working as designed.
Please review this article on touch mode and the use of the "selected" state, then adjust your UI design to follow Android conventions. Selection is only used when the user navigates with the pointing device, not when the user uses the touch screen.
Related
I have a listview and a corresponding listview adapter.
The views displayed in the Listview have I written myself and it's a framelayout with one button and one imagebutton. The imagebutton is a red cross that deletes the entry and the regular button selects the entry.
When the user presses the regular button, that item is selected and I want to show this to the user by setting the background of that item to green. The application stores which item the user selected and the next time the listview is rendered, THAT item should be selected and green.
Notice that there should be one and EXACTLY one selected item in my listview at all times.
In the getView(.. method in my adaper, it's very easy to change color of the button when the user clicks it. But the button that was green before the user clicked is impossible for me to reference.
I tried storing a reference the previously selected button, but it never repainted
I tried removing and adding the data item from the list to trigger notifyDataSetChanged but it never repainted
I tried setChoiceMode(ListView.CHOICE_MODE_SINGLE), but that led nowhere because I don't know how to catch the choice in my getView method and paint differently depending on wheter it's selected or not.
All guides I see suggest using notifyDataSetChanged. However, the underlying data is NOT changed in this case and it is not correct (or possible) solution.
So I think that my problem boils down to: HOW can I reference another view in my listview??
(And Yes, I have seen this post: Highlight selected item in ListView on Android . It describes my problem and is answered with "and then change the color of previous selected item's background back to normal" but I still can't refer to the PREVIOUS selected item.
Thanks!
Why don't you use Radio Buttons ? This is exactly the design you need. You can add a "red cross" on each line to delete the line. The selected line is unique and you can iterate on RadioButton.isChecked(); of your RadioGroup to set the background color accordingly.
I am new to android programming. I have this problem that I created a listView with button and text. I wanted all of this object to be active. Meaning I can click or touch any of these 3. The main idea is, I will display a listview of products. When I select a list it will bring me to a details view. And when I click a button it will add the current selection + 1 to the current textbox. I also want the textbox to be editable.
Take a look at my WaddleAddressBook
The EfficientAdapter has code on how to implement each item.
The WaddleAddressBook shows an example of detecting gestures (swipe left and right in this case).
search.xml is the list item layout.
Each list item basically had a contact picture, contact name and 3 buttons under the contact name for call, sms and edit. You could swipe right to call and left to sms just like on Samsung phones... I never ended up finishing the address book but I hope it helps you.
I have created a custom ListView.. every element of my ListView constructing from a layout.
My layout will have some TextViews and a ToggleButton. My ListView will have some 50 elemnts and my device screen can show 2 elements at a time.
Now if we select ToggleButton on a Item and scroll down my ListView , the selected item will be out of screen and when I come back to the previous selected item I am observinf that selection for that toggle button is gone.
I know that this is a normal behavior in android that It will construct the elements which is currently displaying.
But I want to keep that value.. Is there any way that we preserve selection. or can I tell ListView to donot construct every time.. memory is a not a issue for my application.
Please let me know if there's any good solution for this.
You could store the states of the checkbox in a map with the position as the key. So whenever the list reloads after scroll, it loads based on the hashmap state. You should write this logic in the getView()
I have a ListActivity that presents a list of names from a database using a SimpleCursorAdapter. I want the user to be able to select 1 or more names by clicking them and then proceed to the next Activity. This should be a toggle, so that if the user clicks a selected name it will become de-selected. The underlying code is working fine, the problem is how to show the user which items are currently selected.
I looked at this solution: Android how to highlight a selection in a list and tried toggling .setSelected() on the TextView for the name. The problem is that the "selected" state apparently can only be true for one item in a list at a time. So if the user touches "Alice" then "Bob," only "Bob" will show as selected. Any thoughts on the best way to have a toggle-able highlight for multiple list items?
Have a look at the setChoiceMode method of the AbsListView class and its possible CHOICE_MODE_MULTIPLE parameter value.
I am displaying a radio schedule in a List View and would like to highlight the currently playing program. I also want to allow the user to click on any program and get more details for the program. I have tried the following:
radioView.setSelection(adapter.getCurrentProgramIndex());
radioView.setSelected(true);
This does scroll the list down to the selection which is good, but it does not highlight the selection. I understand this is because the device is not in touch mode, but how then would I go about highlighting the current program?
how then would I go about highlighting
the current program?
Change something in that list row. For example, perhaps you have an icon you can switch to be a "playing" icon, or have an icon that is formerly INVISIBLE become VISIBLE, or something.
Bear in mind that you will need to have these smarts in your row binding code, so that if the user scrolls, you correct undo and redo that setting -- otherwise, row recycling will make it appear that other programs are playing.