In following list, when I click any item which has width equal to 2 lines (in below eg, CNX SMALLCAP), item gets highlighted appropriately.
Problem comes when I click any item which has width equal to 1 line (in below eg, ICICI BANK), then along with the clicked item half of the above and below item is also getting highlighted.
Highlighting is always using width=2 lines.
What can be done to remove this?
I tried using clearFocus() and clearAnimation() inside onListItemClick() , but no luck.
ANY HELP WILL BE LIFE-SAVER !!!
Since you have two lines, focusing both the lines when you have some content makes sense. Hence make the line which you are not using invisible or gone. You can also create separate custom adapter for your listview with single line.
I think you set the selected color on the ListView not into the ListView item i.e. TextView which you have display as item. You can either set selected color on TextView or just set the textview background color as #00000000
<TextView android:background="#00000000" />
using this you define the transparency of the textview color with this
Related
I have an android app which uses a ListView. When I click on any item, there is a light gray color which appears and fades out. How can I make this gray color to remain on the selected item instead of disappearing? Please take a look at the gif which shows the scenario which I want to avoid.
Current Scenario
First of all you need to change background color on clicked.
take reference from here
And then add this line inside your listview's OnItemClickListener
listView.setSelection(int position);
You can set item Selected according to your need using this method
listView.setSelection(0);
listView.getSelectedView().setSelected(true);
OR
listView.setItemChecked(0, true)
I'm using a custom Spinner in a dialog mode. Each item element has one text. The text in each item line is very short, eg. "A", "AB", "BC", etc. In order to select a line I have to click exactly the text (the background is than changing into blue and the item is selected correctly). When I click outside this short text but in the item line it is not selected. Is it possible to force the selection when I click the item line not exactly the item text?
If you are using a custom spinner then you should be able to access the textview element in the xml for the class.
In this xml, the textview element try changing the property
Android:layout_width="match_parent"
You may also use the padding and margin to adjust the same.
Scenario.
Say list view has 5 items. When I click on a particular item, that particular item gets highlighted. When i click on another item, the previous item is unselected and the new item is highlighted.
I am able to do so by holding 2 views. CurrentSelectedItemView and PreviousSelectedItemView. Using these two views I am changing the text color and backgrounds of these two rows. But how do i change the color and background of other rows. I do not want to reset the adapter every time a row is selected.
Say text color is black and background is white. When a row is selected,the colors reverse. For other rows,I need to change the text color to grey. I able to do fr 2 rows only... current and previous.
Is there any simple way of doing this?
You should keep track of last selected index to change the background of previous selected item.
To make changes in listview you need to alteast called adapter.notifydatachanged()
I have a ListView on my fragment which contains multiple items. What I need to do is put an arrow indicator (like this : ►) when one item is selected. I was able to put a border on the item chosen but the application requirement states that arrow (or any other symbol) is also needed to clearly show the current selected item. Any ideas will be highly appreciated. Thanks!
put the arrow indicator in your item layout, and set the
android:visibility="GONE"
or
android:visibility="INVISIBLE"
in your getView() method, set the visibility of the arrow indicator based on wether the item is selected.
when item selection status changed, call
adapter.notifyDataSetChanged();
to refresh your ListView.
Set OnItemClickListener to your ListView. In onItemClick method you get the view which you have clicked. In this method you can findById your view with arrow indicator and set visibility to VISIBLE for show.(by default it hasGONE or INVISIBLE).
Of course you can create a view with arrow indicator and add it after clicked.
I have a table in which I add rows dynamically. By default when a row is clicked, nothing is changed so user can't get notification of which row is seected. I want to set the default theme background color for onClick event of row. The main purpose of this is to match its selection with other components of the application.
EDIT :
To make it simpler and easy to understand, here's the exact scenario :
I have a tablayout, that has a tablelayout in it. I am adding TableRow's dynamically that contians 3 TextView's.
On selecting a tab, its color changes fron Gray to Whitish. I want the same color setting to be done on my row selected.
In any situation, I want to make sure that whatever is the color for tab selection that same color is applied to row selection.
This is what my exact requirement is and am looking for a solution from last 2 days. But can't find anything proper.
At present I am changinf row selection by :
currSelectedRow.setBackgroundResource(android.R.drawable.divider_horizontal_bright); // .list_selector_background);
"list_selector_background" occupies that much length below the row and on next row selection that spcae is not evned out. So spaces are left between rows here and there. Similarly, I also tried with "tab...." that also caused the almost same results as list_selector. At present have just used "divider_horizontal_bright" to get the idea of which row is selected. But doesn't get my solution.
I want the selectedtion background colro of tab to be applied to background color of row.
How do I get this info and set the color of the row selected ?
Thanks #Krishna,
But that didn't work out for me. I implemented using onFocusListener and onClick on Table Row and that worked out perfectly. I wanted to use selector, but I guess ..