1

I'm new to android and struggling in changing the height of the dropdown list's height of a spinner. I'm using the following code to inflate my spinner.

code

 String[] fil_array = { "Starts with", "Contains" };
    ArrayAdapter<String> m_FilterAdap = new ArrayAdapter<String>(
            Mse_Customer.this, android.R.layout.simple_spinner_item, fil_array);
    m_Filter.setAdapter(m_FilterAdap);

Please can anyone guide me how to achieve it. Please have a look over the attached image for more clarity. The second image working correctly with the same type of code.Really confused why it is happening.

enter image description here

enter image description here

3
  • 1
    instead of using a built-in layout crate your own with the height you want for each row Commented Aug 18, 2015 at 17:43
  • Without using any customArrayAdapter...It is possible? @tyczj Commented Aug 18, 2015 at 17:45
  • 1
    you dont need a custom array adapter to use a view you created, just pass in the resource id plus the data array and the resource fields Commented Aug 18, 2015 at 17:47

3 Answers 3

1

don't use android.R.layout make your own custom layout

layout_spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8.0dip"
    android:text="Text"
    android:textSize="20.0sp" />

String[] fil_array = { "Starts with", "Contains" };
ArrayAdapter<String> m_FilterAdap = new ArrayAdapter<String>(
        Mse_Customer.this, R.layout.layout_spinner_item, fil_array);
m_Filter.setAdapter(m_FilterAdap);
Sign up to request clarification or add additional context in comments.

1 Comment

Its really helpful but the height of the the dropdown of the spinner is of the same size as the size of the text in it.Its not coming like the second image that i have attached. @ kishore jethva
0

Create custom_spinner_item.xml

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:layout_marginTop="6dp"
    android:layout_marginBottom="6dp" />

Then in your code, replace:

ArrayAdapter<String> m_FilterAdap = new ArrayAdapter<String>(Mse_Customer.this, android.R.layout.simple_spinner_item, fil_array);

with

ArrayAdapter<String> m_FilterAdap = new ArrayAdapter<String>(Mse_Customer.this, R.layout.custom_spinner_item, fil_array);

1 Comment

I tried the way you mentioned above...but the dropdown list of Spinner doesn't expand(as in second image).I tried by changing the margin top and bottom also...but nothing worked. @ Hussein El Feky
0

create custom drop_down_spinner_item in xml and set: layout_height="wrap_content" and minHeight="40dp";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.