title: How to reset data of NumberPicker
body: <p>I am using two <a href="https://github.com/SimonVT/android-numberpicker" rel="noreferrer">NumberPicker</a>s to display province(<code>mProvincePicker</code>) and city(<code>mCityPicker</code>) data in my app. When user changes province data, city data should be changed accordingly. I reset the <code>mCityPicker</code> data in <code>NumberPicker.onValueChange(NumberPicker picker, int oldVal, int newVal)</code>. But it does not work well and an <code>java.lang.ArrayIndexOutOfBoundsException</code> crash the app.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class AreaPickerDialog extends Dialog implements OnValueChangeListener, OnClickListener {
      static final String TAG = "AreaPickerDialog";
  
      private NumberPicker mProvincePicker;
      private NumberPicker mCityPicker;
      private Button mCancelBtn;
      private Button mOKBtn;
  
      private AreaUtil mAreaUtil;
      private List&lt;Area&gt; mProvinces;
      private int mAreaId;
      private int mProvinceId;
      private Handler mHandler;
  
      public AreaPickerDialog(Context context, Handler handler, int areaId) {
          super(context);
          mAreaUtil = AreaUtil.getInstance();
          mProvinces = mAreaUtil.getProvinceList();
          mAreaId = areaId;
          mProvinceId = mAreaUtil.getProvinceIdByAreaId(areaId);
          mHandler = handler;
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.dialog_area_picker);
          mProvincePicker = (NumberPicker) findViewById(R.id.np_province);
          mCityPicker = (NumberPicker) findViewById(R.id.np_city);
          mCancelBtn = (Button) findViewById(R.id.btn_cancel);
          mOKBtn = (Button) findViewById(R.id.btn_ok);
  
          initProvinceData();
  
          mProvincePicker.setOnValueChangedListener(this);
          mCityPicker.setOnValueChangedListener(this);
          mCancelBtn.setOnClickListener(this);
          mOKBtn.setOnClickListener(this);
      }
  
      private void initProvinceData() {
          if (mProvinces != null &amp;&amp; mProvinces.size() &gt; 0) {
              String[] provinceNames = new String[mProvinces.size()];
              for (int i = 0; i &lt; provinceNames.length; i++) {
                  provinceNames[i] = mProvinces.get(i).getProvincename();
              }
              mProvincePicker.setDisplayedValues(provinceNames );
              mProvincePicker.setMinValue(1);
              mProvincePicker.setMaxValue(mProvinces.size());
          }
          mProvincePicker.setValue(mProvinceId);
          initCityData(mProvincePicker.getValue());
      }
  
      private void initCityData(int provinceId) {
          List&lt;Arealist&gt; cities = mAreaUtil.getCityListOfProvince(provinceId);
          if (cities != null &amp;&amp; cities.size() &gt; 0) {
              try {
                  int min = Integer.parseInt(cities.get(0).getAreaid());
                  int max = Integer.parseInt(cities.get(cities.size() -1).getAreaid());
                  String[] cityNames = new String[cities.size()];
                  for (int i = 0; i &lt; cityNames.length; i++) {
                      cityNames[i] = cities.get(i).getName();
                  }
                  mCityPicker.setValue(0);
                  mCityPicker.setDisplayedValues(cityNames);
                  mCityPicker.setMinValue(min);
                  mCityPicker.setMaxValue(max);
              } catch (NumberFormatException e) {
                  ILog.e(TAG, e.getMessage(), e);
              }
          }
      }
  
      @Override
      public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
          if (mProvincePicker.equals(picker)) {
              initCityData(mProvincePicker.getValue());
          } else if (mCityPicker.equals(picker)) {
              mAreaId = mCityPicker.getValue();
          }
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
          case R.id.btn_cancel:
              dismiss();
              break;
  
          case R.id.btn_ok:
              Message msg = mHandler.obtainMessage(MineActivity.MSG_UPDATE_AREA);
              msg.arg1 = mAreaId;
              msg.sendToTarget();
              dismiss();
              break;
  
          default:
              break;
          }
      }
  } 
  </code></pre>
  
  <p>And logcat error trace:</p>
  
  <pre><code>12-30 23:09:26.560: E/InputEventReceiver(5620): Exception dispatching input event.
  12-30 23:09:26.560: W/dalvikvm(5620): threadid=1: thread exiting with uncaught exception (group=0x41ddf438)
  12-30 23:09:26.580: E/AndroidRuntime(5620): FATAL EXCEPTION: main
  12-30 23:09:26.580: E/AndroidRuntime(5620): java.lang.ArrayIndexOutOfBoundsException: length=14; index=15
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.updateInputTextView(NumberPicker.java:1840)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.setDisplayedValues(NumberPicker.java:1423)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at com.meishai.app.dialog.AreaPickerDialog.initCityData(AreaPickerDialog.java:88)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at com.meishai.app.dialog.AreaPickerDialog.onValueChange(AreaPickerDialog.java:100)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.notifyChange(NumberPicker.java:1855)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.setValueInternal(NumberPicker.java:1641)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.scrollBy(NumberPicker.java:1106)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.onTouchEvent(NumberPicker.java:886)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at android.view.View.dispatchTouchEvent(View.java:7127)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
  12-30 23:09:26.580: E/AndroidRuntime(5620):     at net.simonvt.numberpicker.NumberPicker.dispatchTouchEvent(NumberPicker.java:944)
      ....
  </code></pre>
  
  <p>I am reseting the <code>minValue,maxValue and DisplayedValues</code> to reset the <code>NumberPicker</code> data and not working, so what is the right way?</p>