-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.

nats
  • 1
  • 1
  • 1
  • refer http://stackoverflow.com/questions/20597584/how-to-limit-the-height-of-spinner-drop-down-view-in-android – sasikumar Feb 22 '16 at 07: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. – nats Feb 22 '16 at 07:12
  • you can adjust height based on your phone size..in that link code height is 500. – sasikumar Feb 22 '16 at 07:14
  • @sasikumar I have tried that , still didn't work. it still takes up the full height of the screen. – nats Feb 25 '16 at 10:19

1 Answers1

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);
}
droidev
  • 7,352
  • 11
  • 62
  • 94