1. Download our Official Android App: Forums for Android!

Apps spinner with numbers

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

  1. clauswilson

    clauswilson Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 25, 2010

    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
    Rank:
    None
    Points:
    38
    Posts:
    105
    Joined:
    May 15, 2010

    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 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Jul 25, 2010

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