0

I have four wheels which spin with the numbers 0-9:

enter image description here

I want to be able to input words into each of the wheels from four different arrays so each wheel would have its own specific array of words.

The code is posted below and would be very helpful if someone could take a look and edit the code to correct it.

public class PasswActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.passw_layout);
        initWheel(R.id.passw_1);
        initWheel(R.id.passw_2);
        initWheel(R.id.passw_3);
        initWheel(R.id.passw_4);

        Button mix = (Button)findViewById(R.id.btn_mix);
        mix.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mixWheel(R.id.passw_1);
                mixWheel(R.id.passw_2);
                mixWheel(R.id.passw_3);
                mixWheel(R.id.passw_4);
            }
        });
   }

   // Wheel scrolled flag
   private boolean wheelScrolled = false;

   // Wheel scrolled listener
   OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
        public void onScrollingStarted(WheelView wheel) {
            wheelScrolled = true;
        } 
        public void onScrollingFinished(WheelView wheel) {
            wheelScrolled = false;
        }
   };

   // Wheel changed listener
   private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
         public void onChanged(WheelView wheel, int oldValue, int newValue) {
             if (!wheelScrolled) {

            }
         }
   };


    /**
      * Initializes wheel
      * @param id the wheel widget Id
     */
    private void initWheel(int id) {
          WheelView wheel = getWheel(id);
          wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 9));
          wheel.setCurrentItem((int)(Math.random() * 10));

          wheel.addChangingListener(changedListener);
          wheel.addScrollingListener(scrolledListener);
          wheel.setCyclic(true);
          wheel.setInterpolator(new AnticipateOvershootInterpolator());
    }

    /**
     * Returns wheel by Id
     * @param id the wheel Id
     * @return the wheel with passed Id
    */
    private WheelView getWheel(int id) {
         return (WheelView) findViewById(id);
    }

    /**
    * Tests entered PIN
      * @param v1
      * @param v2
      * @param v3
      * @param v4
      * @return true 
     */
     private boolean testPin(int v1, int v2, int v3, int v4) {
       return testWheelValue(R.id.passw_1, v1) && testWheelValue(R.id.passw_2, v2) &&
        testWheelValue(R.id.passw_3, v3) && testWheelValue(R.id.passw_4, v4);
     }

    /**
     * Tests wheel value
     * @param id the wheel Id
     * @param value the value to test
     * @return true if wheel value is equal to passed value
    */
    private boolean testWheelValue(int id, int value) {
            return getWheel(id).getCurrentItem() == value;
    }

     /**
     * Mixes wheel
     * @param id the wheel id
     */
     private void mixWheel(int id) {
            WheelView wheel = getWheel(id);
            wheel.scroll(-25 + (int)(Math.random() * 50), 2000);
     }
}
Machavity
  • 30,841
  • 27
  • 92
  • 100
Matt
  • 1,747
  • 8
  • 33
  • 58
  • look at your NumericWheelAdapter class and see what it uses to construct adapter –  Nov 18 '11 at 10:53
  • You might post it here as well, so we can help you to modify it according to your need –  Nov 18 '11 at 11:04
  • Sorry i am pretty new to andorid could you tell me what you mean exactly and what do you need me to post? – Matt Nov 18 '11 at 11:07
  • this line: wheel.setViewAdapter(new NumericWheelAdapter(this, 0, 9)); | Here you create a new Adapter for your wheel adapter. YOu are supposed to have a class called 'NumericWheelAdapter' which fills your adapter with information like (0...9), so can you edit your question and paste your 'NumericWheelAdapter' class –  Nov 18 '11 at 11:10
  • I have change it to use ArrayWheelAdapter which can be viewed here http://code.google.com/p/android-wheel/source/browse/trunk/wheel/src/kankan/wheel/widget/adapters/ArrayWheelAdapter.java this is what i changed it to (new ArrayWheelAdapter(new String[]{"Abc", "Foo", "Bar"} – Matt Nov 18 '11 at 11:23
  • No it gives me the error The constructor ArrayWheelAdapter(String[]) is undefined i think i need to create somehting in that file ArrayWheelAdapter – Matt Nov 18 '11 at 11:33
  • Yeah, string is undefined, because class uses the generic type T. Since you cannot cast from string to generic type, try to edit your class, so that it will operate on Strings, not T. –  Nov 18 '11 at 11:43

2 Answers2

1

In Android Picker widget from http://code.google.com/p/android-wheel/ I have forked a project using http://android-wheel.googlecode.com/svn/trunk/

Then I have imported a new Android project - WheelDemo from source in my Eclipse IDE. After that I changed: in WheelDemo.java:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    //Since another activity is being called in this way,
    //I am sending a list with every intent, but this can be changed

    Map map = (Map) l.getItemAtPosition(position);

    ArrayList<String> list = new ArrayList<String>();
    list.add("One");
    list.add("Two");

    Intent intent = (Intent) map.get("intent");
    intent.putStringArrayListExtra("list", list);
    startActivity(intent);
}

In CitiesActivity.java:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.cities_layout);
        String[] arrayString = null;

        ArrayList<String> list = new ArrayList<String>();
        list = getIntent().getExtras().getStringArrayList("list");

        if (list != null) {
            arrayString = new String[list.size()];
            if (!list.isEmpty()) {
                for (int i = 0; i < list.size(); i++)
                    arrayString[i] = list.get(i);
            } else
                System.out.println("list is empty");
        } else
            System.out.println("list is null");

        final WheelView country = (WheelView) findViewById(R.id.country);
        country.setVisibleItems(3);
        country.setViewAdapter(new CountryAdapter(this));

        final String cities[][] = new String[][] {
                new String[] { "New York", "Washington", "Chicago", "Atlanta",
                        "Orlando" },
                new String[] { "Ottawa", "Vancouver", "Toronto", "Windsor",
                        "Montreal" },
                new String[] { "Kiev", "Dnipro", "Lviv", "Kharkiv" },
                arrayString, };

.....

And then I get such a picture:

Wheel Widget Android

P.S. I have used WheelDemo source code, not Wheel one

0

Within source (kankan.wheel.widget) you have also ArrayWheelAdapter class, use it instead od NumericWheelAdapter calass

Jova
  • 499
  • 4
  • 9
  • I have tried changing it to new ArrayWheelAdapter(null, new String[]{"Abc", "Foo", "Bar"} which gives me no errors but the app force closes if i take the null out it gives me the error The constructor ArrayWheelAdapter(String[]) is undefined – Matt Nov 18 '11 at 11:16
  • You can view all the code here if it helps http://code.google.com/p/android-wheel/source/browse/#svn%2Ftrunk%2Fwheel%2Fsrc%2Fkankan%2Fwheel%2Fwidget%253Fstate%253Dclosed – Matt Nov 18 '11 at 11:17