1. Check out our app, Forums for Android! Download and leave feedback here!

spinner with numbers

Discussion in 'Application Development' started by clauswilson, Jul 25, 2010.

  1. clauswilson

    clauswilson New Member
    Thread Starter
    5

    Jul 25, 2010
    2
    0
    5
    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
    38

    May 15, 2010
    105
    13
    38
    Software Engineer
    West Des Moines, IA
    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
    Thread Starter
    5

    Jul 25, 2010
    2
    0
    5
    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...