2

I have a ListView which handles onClick events by showing a PopUpMenu. However, I want the user to see the little triangle inside the views that can be clicked.

I tried using a Spinner, because that element looks like what I'm after, but I can't set the title of the Spinner to anything other than its options.

Of course I could custom make everything but as this is not a new pattern I thought maybe there's already something out there. I just can't find it myself.

Example of what I'm after:

spinner example

Maarten
  • 6,894
  • 7
  • 55
  • 90

2 Answers2

1

Perhaps you are looking for the prompt attribute that you can set for a spinner?

Beyond that, I would suggest using the SlideExpandableListView if you haven't already invested too much time in your current implementation and if that is the pattern that you would like to achieve:

This library allows you to have custom listview in which each list item has an area that will slide-out once the users clicks on a certain button.

saschoar
  • 8,150
  • 5
  • 43
  • 46
  • I was actually looking for something that does a `PopUpMenu`, but this looks pretty sweet as well. Thanks! – Maarten Jan 13 '13 at 20:33
  • As far as the prompt text goes, I think they dropped it since Honeycomb: `The prompt to display when the spinner's dialog is shown.` It doesn't show up in my tests either. – Maarten Jan 13 '13 at 21:04
  • Ok, didn't know it was for the dialog only, sorry for the confusion. Nevertheless, there are some more approaches here: http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one – saschoar Jan 13 '13 at 21:24
1

If you use ActionBarSherlock, you can use the triangle ABS uses:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        etc />

    <ImageView
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:contentDescription="@string/expand_triangle"
        android:src="@drawable/abs__spinner_ab_default_holo_light" />

</RelativeLayout>
Maarten
  • 6,894
  • 7
  • 55
  • 90