i have a four wheel picker with words in each wheel my problem at the moment is that each wheel is pulling in the same words you can see the code below.
My question is can someone help me in giving each of the wheels there own arrays of words. In the XML below you can see each wheel has its own ID but i cannot figure out how to use them in the java so each wheel has its own specific array.
private void initWheel(int id) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc", "Foo", "Bar"}));
wheel.setCurrentItem((int)(Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
private WheelView getWheel(int id) {
return (WheelView) findViewById(id);
}
My XML is
<kankan.wheel.widget.WheelView
android:id="@+id/passw_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/passw_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/passw_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="@+id/passw_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Use a different instance of ArrayWheelAdapter
for each instance of WheelView
. That way you can customise the list that is displayed in each WheelView
.
<UPDATE>
The key line is this one:
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc", "Foo", "Bar"}));
This is where you are specifying the items that will appear in each WheelView
. You are creating a new instance of ArrayWheelAdapter
for each instance of WheelView
, but they all contain the same set of String values - and these are what is appearing in your WheelView
controls.
Maybe you should try something like:
private void initWheel(int id, String[] values) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, values));
wheel.setCurrentItem((int)(Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
Then supply different values to initWheel
:
initWheel( R.id.passw_1, new String[] { "Abc", "Foo" } );
initWheel( R.id.passw_2, new String[] { "Def", "Bar" } );