private void initiWheelView() { province = getResources().getStringArray(R.array.province); areaWheelView.setAdapter( new ArrayWheelAdapter<String>(getResources().getStringArray(citytoarea[18][2]))); areaWheelView.setVisibleItems(5); areaWheelView.setCurrentItem(0); cityWheelView.setAdapter( new ArrayWheelAdapter<String>(getResources().getStringArray(city[18]))); cityWheelView.setVisibleItems(5); cityWheelView.setCurrentItem(2); provinceWheelView.setAdapter(new ArrayWheelAdapter<String>(province)); provinceWheelView.setVisibleItems(5); provinceWheelView.setCurrentItem(18); OnWheelChangedListener wheelListener = new OnWheelChangedListener() { @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { System.out.println("wheel-->" + wheel.getId()); System.out.println("oldValue-->" + oldValue); System.out.println("newValue-->" + newValue); } }; provinceWheelView.addChangingListener(wheelListener); cityWheelView.addChangingListener(wheelListener); OnWheelScrollListener scrollListener = new OnWheelScrollListener() { @Override public void onScrollingStarted(WheelView wheel) { // TODO Auto-generated method stub } @Override public void onScrollingFinished(WheelView wheel) { System.out.println("wheel-->" + wheel.getId()); System.out.println("wheel-->" + wheel.getCurrentItem()); switch (wheel.getId()) { case 2131099651: setCity(wheel.getCurrentItem()); provinceId = wheel.getCurrentItem(); setArea(provinceId, 0); break; case 2131099652: setArea(provinceId, wheel.getCurrentItem()); break; } } }; provinceWheelView.addScrollingListener(scrollListener); cityWheelView.addScrollingListener(scrollListener); }
public void setArea(int provinceId, int cityId) { Log.i("setArea", "provinceId=" + provinceId + " cityId=" + cityId); int length = citytoarea[provinceId].length; Log.i("setArea", "citytoarea[provinceId].length=" + length); areaWheelView.setAdapter( new ArrayWheelAdapter<String>( getResources().getStringArray(citytoarea[provinceId][cityId]))); areaWheelView.setVisibleItems(5); areaWheelView.setCurrentItem(0); }
public void setCity(int provinceId) { cityWheelView.setAdapter( new ArrayWheelAdapter<String>(getResources().getStringArray(city[provinceId]))); cityWheelView.setVisibleItems(5); cityWheelView.setCurrentItem(0); }