spinner with numbers


Last Updated:

  1. clauswilson

    clauswilson New Member This Topic's Starter

    Joined:
    Jul 25, 2010
    Messages:
    2
    Likes Received:
    0
    I need to use a spinner going from 4 to 100.
    All I can find on the web is spinner and string array examples using ArrayAdapter.
    Please help.
    Claus
     

    Advertisement
  2. andywhoa

    andywhoa Well-Known Member

    Joined:
    May 15, 2010
    Messages:
    105
    Likes Received:
    13
    I've never used a spinner, but I'm sure theres a corresponding function for ints like there is to insert Strings into the spinner. If not, use Integer.toString(yourint); to convert the int into a String

    Code (Text):
    1. for(int i =4; i<=100; i++) {
    2.   // insert i into spinner
    3. }
     
  3. clauswilson

    clauswilson New Member This Topic's Starter

    Joined:
    Jul 25, 2010
    Messages:
    2
    Likes Received:
    0
    Here's my code:
    //private constants
    private static final int MIN = 4;
    private static final int MAX = 100;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    (...)
    //private Adapters for setting values to UI
    String[] np = new String[MAX-MIN];
    for(int i=MIN;i<=MAX;i++){
    np[i-4]=Integer.toString(i);
    }
    ArrayAdapter <String> _aa = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,np);//array holding min and max pages
    _spinner.setAdapter(_aa);
    }
    (...)
    }
     

Share This Page

Loading...