-1

How should I go about limiting the height of a spinner drop down ?
Suppose for example:

If I have a spinner drop down with total of 10 rows,
I would like to display only the first 3 rows,
and the rest of the content should be scrollable.

4
  • refer stackoverflow.com/questions/20597584/… Commented Feb 22, 2016 at 7:08
  • @sasikumar I have tried the accepted answer from the link which uses reflection. But , it didn't work for me. Using that answer, i get a dialog type dropdown which covers the entire screen. Commented Feb 22, 2016 at 7:12
  • you can adjust height based on your phone size..in that link code height is 500. Commented Feb 22, 2016 at 7:14
  • @sasikumar I have tried that , still didn't work. it still takes up the full height of the screen. Commented Feb 25, 2016 at 10:19

1 Answer 1

0

There is no default method in spinner to control number of items to display in drop-down. you can create your own spinner. refer this link, he has created a custom spinner that supports setVisibleItemNo (int no) method. you can try it. I didn't test it .but the code seems to be working. you can give a try.

/**
 * Set the height of DropDown spinner equal to number of visible rows
 * 
 * @param no
 *            - number (Integer) of visible item row
 */
public void setVisibleItemNo(int no) {
    this.visibleItemNo = no;
    setListViewHeightBasedOnChildren(lv);
}
Sign up to request clarification or add additional context in comments.

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.