4451

row of listView remains underLined

Question:

i have a listView , and i'm not figuring out on how to underLine the row selected only for the time i click on it. With this code the row selected remains underlined after clicking on it and disappear when i select a new row.

<ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/list_background" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="1dp" android:listSelector="@drawable/list_selector" />

list selector:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/> <item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/> </selector>

is it possible to achieve this feature?

<strong>UPDATE</strong>

i want to achieve this feature.

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/GZoJZ.png" data-original="https://i.stack.imgur.com/GZoJZ.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

and after

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/bImzF.png" data-original="https://i.stack.imgur.com/bImzF.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

with this code the selected row doens't do what is described into screenshots,this one remains underlined.

thanks in advance.

Answer1:

I think it would be helpful for you . in your list_selector xml file please add this code

<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_enabled="false" android:state_focused="true" android:drawable="@android:color/black" /> <item android:state_pressed="true" android:drawable="@android:color/holo_red_dark" /> <item android:state_focused="true" android:drawable="@android:color/holo_red_dark" /> </selector>

this code is work fine for me .. if face any problem then comment .. Thank you<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/Yk4lp.png" data-original="https://i.stack.imgur.com/Yk4lp.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Recommend

  • repeating animation with Timer
  • Set the height of imageview according to screen from the layout
  • how add and delete rows to table layout in java programically
  • Click event on EditText's drawableRight not working properly?
  • How to make a Button align to the right in a layout?
  • Android : Create an activity and use it many times with different data [closed]
  • screen with top banner, webview and bottom banner
  • Custom Spinner TextView is being cut off
  • View disappears after setting height of gridLayout to wrap_content
  • TextView shadow not showing up in preview - although working on real device
  • Edittext requestFocus() dynamically not working
  • onMeasure() called with EXACTLY and spec size 0
  • I can't show LinearLayout at bottom to scroll view
  • Can I override some attribute of drawable shape?
  • Close button for AdMob banner
  • Sticky Footer Below ListView in Android Layout
  • Overlapping ImageView in RelativeView
  • Android custom dialog linearlayout size same as dialogs bg image
  • Android : Strike out Text with bold or thicker line than default STRIKE_THRU_TEXT_FLAG
  • Background image crashes android
  • How to automatically pop-up keyboard?
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • EditText ignores the ImeActionLabel
  • Gray line inside cardview :)?
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • How can I speed up CURL tasks?
  • Google Custom Search with transparent background
  • Disable Enter in editText android
  • Android fill_parent issue
  • Highlight and Bold text in JTextPane
  • Algorithm for a smudge tool?
  • Repeat a vertical line on every page in Report Builder / SSRS
  • Debugging ASP.NET on a built-in web server suddenly stops
  • How reduce the height of an mschart by breaking up the y-axis
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • python regex in pyparsing
  • Android Google Maps API OnLocationChanged only called once
  • How can I use threading to 'tick' a timer to be accessed by other threads?