title: Preset number picker for android
body: <p>This is my first post on stackoverflow, so feel free let me know if I'm doing anything wrong.</p>
  
  <p>I'm working on making an android app. For one of my menu activity's I need some sort of widget that will allow the user to pick a number from a predefined set. (ie: {50, 100, 200, 500, 1000, 2000})</p>
  
  <p>I looked at the Spinner, SeekBar, and NumberPicker Widgets, and here's the problems I've found with each.</p>
  
  <ul>
  <li>The Spinner seems to only allow strings.</li>
  <li>The SeekBar and NumberPicker don't seem to easily allow preset values.</li>
  </ul>
  
  <p>Would any of these widgets work for what I'm trying to do? If not, is there another widget that might work better? If not, then how would you recommend I go about this?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I tried using a spinner and the <code>Integer.parseInt</code> function. I got a null pointer exception:</p>
  
  <pre><code>02-11 18:21:23.823: E/AndroidRuntime(359): Caused by: java.lang.NullPointerException
  02-11 18:21:23.823: E/AndroidRuntime(359):  at com.Package.Jigsaw.PuzzleActivity.onCreate(PuzzleActivity.java:20)
  </code></pre>
  
  <p>Line 20 of PuzzleActivity is the one where I'm declaring numPc.</p>
  
  <p>Here's the relevant bits of code:</p>
  
  <p><em>Menu Activity:</em></p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.new_puzzle);
  
      //final Gallery gal = (Gallery) findViewById(R.id.opt_img);
  
      final Spinner numPc = (Spinner) findViewById(R.id.opt_numpc);
      ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
              this, R.array.opt_numpc_options, android.R.layout.simple_spinner_item);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      numPc.setAdapter(adapter);
  
  ...snip...
  
          Button start_btn = (Button) findViewById(R.id.start_puzzle_btn);
      start_btn.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              // TODO Auto-generated method stub
              Intent i = new Intent("us.kniffin.Jigsaw.OPENPUZZLE");
              //i.putExtra("img", gal.getSelectedItem());
              //i.putExtra("numPc", numPc.getSelectedItem());
              i.putExtra("numPc", Integer.parseInt(numPc.getSelectedItem().toString()));
              //i.putExtra("rot", rot.getSelectedItem().toString());
              //i.putExtra("connType", connType.getSelectedItem().toString());
              startActivity(i);
  
          }
      });
  </code></pre>
  
  <p><em>Main Activity (PuzzleActivity):</em></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final PuzzleView v;
      Dimension numPcXY;
  
      // TODO: update this line to read in options
      int numPc = (Integer) savedInstanceState.get("numPc");  
  
      // TODO: update this line to read in options
      picture = BitmapFactory.decodeResource(getResources(), R.drawable.test_pic);
      picture = Bitmap.createScaledBitmap(picture, picture.getWidth()/3, picture.getHeight()/3, false);
  
      // Do some math to do a case statement to determine numPcX and numPcY 
      numPcXY = calcXYpieces(numPc, picture);
  
      // Create the puzzle
      pieces = new PuzzlePieceSet(picture, numPcXY.getX(), numPcXY.getY());
  
      v = new PuzzleView(this, pieces);
      setContentView(v);
  
      pieces.scramble();
  }
  </code></pre>