1

How do I apply an ellipsis to the spinner instead of the dropdown views? When I search for terms like spinner custom view, spinner ellipsis or spinner long text I get results for the views in the dropdown. For example:

This is not what I'm looking for, I'm looking for the actual spinner text.

An image to illustrate my problem

enter image description here

The content is Recipe for disaster/Freeing king awowogei but the spinner tries to place it on the next line, which is what I do not want. Instead it should add ellipsis at the end and displaying Recipe for disaster/Freeing king awo... or something.

The spinner content is loaded from a string array and a custom adapter, this all works fine.

I've tried adding

android:ellipsize="marquee"
android:singleLine="true"

To my custom dropdown view, but that's not working. The spinner does not have properties regarding text wrapping so I cannot find out how to achieve this.

The container for the Spinner has a height of 50dp because I do not want the spinner to be higher than that.

And in case it's relevant the simplified xml code of the views

quest_row.xml the view that I use in my adapter

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/input_background_color"
    android:orientation="horizontal"
    android:padding="5dp">

    <TextView
        android:id="@+id/quest_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:textColor="@color/text"
        android:textSize="18sp"/>
</LinearLayout>

quest.xml the main layout

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <Spinner
        android:id="@+id/quest_selector_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:dropDownWidth="wrap_content"
        android:padding="5dp"/>
</LinearLayout>
Denny
  • 1,766
  • 3
  • 17
  • 37

1 Answers1

0

Put android:ellipsize="end" on the TextView that you are using in your SpinnerAdapter (quest_row.xml, I assume).

Your question shows that you tried android:ellipsize="marquee", which will not work and isn't what you are looking for anyway ("it should add ellipsis at the end").

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for your answer, but that doesn't seem to work. The text inside the spinner is still being wrapped to the next line, like in my image – Denny Sep 29 '18 at 20:00
  • Make sure that you are applying it to the right layout. Usually there are two separate layouts used with a `SpinnerAdapter`, one for the selected view when the `Spinner` is closed and one for the rows in the scrolling list when the `Spinner` is open. – CommonsWare Sep 29 '18 at 20:02
  • Seems to do the trick! Had to override `getView` and `getDropDownView` – Denny Sep 29 '18 at 20:23