1
votes

I have series of elements in android layout as shown in attached image. one of the element is searchview and below searchview, there are other elements. i have written a code to display list items. when i click on searchView, the list items are shown. but i want the list items to be shown on top of /over lay other elements below search view. so when i add "drawSelectorOnTop", list items still not shown on top of other elements.

  <ListView
                android:id="@+id/list_view"
                style="@style/toolbarText"
                android:layout_width="250dp"
                android:layout_height="20dp"
                android:layout_above="@+id/works_in"
                android:layout_alignParentTop="true"
                android:background="@color/white"
                android:drawSelectorOnTop="true"
                android:visibility="visible">

            </ListView>

enter image description here

2
thanks. I have tried. but it is not working. the listview with items not displaying on other elements.user1439582

2 Answers

0
votes

try to set this listview on bottomsheet dialog

0
votes

In addition to add android:drawSelectorOnTop="true", you also need set a Drawable that should be used to highlight the currently selected item.

Two ways:

  1. use android:listSelector xml attribute.

  2. use setSelector method.

And you should create a selector xml in drawable folder like below:

<?xml version="1.0" encoding="utf-8"?>
   <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_selected="true"   
         android:drawable="@color/gray" />
</selector>

suppose the name of this selector xml file is my_selector, then you could do like:

your_list.setSelector( R.drawable.my_selector);