I've got an activity which has a ListView and I've created a custom Adapter based on BaseAdapter.
The GetView method of the custom adapter uses a custom layout:
view = context.LayoutInflater.Inflate(Resource.Layout.BluetoothDeviceListItem, null);
The layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/BluetoothDeviceListSelector">
<TextView android:id="@+id/txtBluetoothDeviceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
style="@android:style/TextAppearance.Large"/>
<TextView android:id="@+id/txtBluetoothDeviceAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
style="@android:style/TextAppearance.Medium"/>
</LinearLayout>
Basically I display the name of the Bluetooth device and it's address underneath.
But I'd like the user to be able to select an item in the ListView and that item should
remain highlighted (at the very least) or I might want to add an icon to it or whatever.
As I understand it, since I'm using a custom layout, I lose the default selection indicator and have to use my own selector. I found something like this in an online tutorial:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#E77A26"
android:endColor="#1DB38B"
android:angle="270" />
</shape>
</item>
<item android:state_selected="true">
<shape>
<gradient
android:startColor="#E77A26"
android:endColor="#2B37AE"
android:angle="270" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient
android:startColor="#E77A26"
android:endColor="#EEFFEE"
android:angle="270" />
</shape>
</item>
</selector>
But the only thing that does is change the color as long as the user presses and holds an item in the ListView. As soon as he lets go, nothing is highlighted anymore.
Now I can't figure out what's really causing the problem.
- Did my ListView lose selection support somewhere along the way
- Is the XML for the Selector simply wrong
- Should I add selection support to the Adapter (which seems strange as it should be independent of the view)
Disclaimer: I've seen a few related questions, but they do not really help me.
also, I'm currently unable to get to most of the online documentation due to the great wall