1

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" />
Machavity
  • 30,841
  • 27
  • 92
  • 100
Matt
  • 1,747
  • 8
  • 33
  • 58

2 Answers2

3

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" } );
Mark Allison
  • 21,839
  • 8
  • 47
  • 46
  • Thanks for your answer but i dont really understand how to implement that could you help me out a bit futher? Thanks. – Matt Nov 18 '11 at 13:06
  • Further detail added to original answer – Mark Allison Nov 18 '11 at 13:15
  • Thanks so much i can see how it is supposed to work now but when i change the code to the word "values" i get this error "values cannot be resolved" also where should the values of iniWheel go without causing them to throw an error. – Matt Nov 18 '11 at 13:22
  • 1
    is it just me or the call should be initWheel( R.id.passw_1, new String[]{"Abc", "Foo"} ); ? – mihail Nov 18 '11 at 13:23
  • Have added `values` to your method arguments as per the first line of the example code? Where do you currently call `initWheel` from? Either post your entire code, or you'll have to work that bit out for yourself. – Mark Allison Nov 18 '11 at 13:25
0

you call this for every WheelView... What do you expect to happen :) ?

wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc", "Foo", "Bar"}));

if you want different arrays you should switch the current id like

switch(id){
  case R.id.passw_1: {wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc1", "Foo1", "Bar1"})); break;}
  case R.id.passw_2: {wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc2", "Foo2", "Bar2"})); break;}
  case R.id.passw_3: {wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc3", "Foo3", "Bar3"})); break;}
  case R.id.passw_4: {wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, new String[]{"Abc4", "Foo4", "Bar4"})); break;}
}

good luck!

mihail
  • 2,173
  • 19
  • 31