miércoles, 21 de marzo de 2012

How to use Android Wheel - Part 1

Do not try to reinvent the wheel... but if you do, make sure is the Android Wheel

Coming from iOS world one thing I really missed when I first started coding in Android was this fancy picker date of iOS, so I looked around Internet and I ran into this project:


It seemed pretty cool to me and just exactly what I was looking for, however I had no idea how to include it into my project; actually is very easy but first I had to struggle a little bit wandering how to start and that’s why I post this small tutorial hoping save time to those who are trying to use Android wheel.

If you go to the Downloads tab in the project Web page the only thing you will get is the apk, but what we need is the source code, so the key is get it via subversion.

If you are working on MAC, subversion is already installed, but if you need type this line on terminal to install it.

To install subversion on Linux type:

For Debian

For Red Hat

To install on Windows I choose the following client:
Once you’ve installed subversion is very straightforward to get the source code, just type on terminal: 


In the path you made the download, you will find two folders: wheel and wheel_demo, the important one obviously is wheel, import it as project in eclipse: File-> Import-> General -> Existing Projects into Workspace and choose the folder “wheel” you just download.




Once we’ve imported the source code, we need to add it as library to our project.

Go to Project-> Properties -> Android, in section Library press the button Add and select the wheel project






Done this we've finish, we can use now Android Wheel Classes to make look cool our app. In a second part for this post I will show an example.

20 comentarios:

  1. I followed the above steps exactly, BUT when I import into Eclipse I get lots and lots of errors in the 'src' files.
    Any suggestions?

    ResponderEliminar
    Respuestas
    1. in wheel-demo project do this:
      in each java file(CitiesActivity for example) change import kankan.wheel.R; with import kankan.wheel.demo.R;

      hope it helps

      Eliminar
  2. me too
    i got the errors on WheelViewAdapter.java file
    how to solve it?
    irsaliv@gmail.com
    thanks

    ResponderEliminar
  3. Hi, Can you give an example of what kind of errors did you get?

    ResponderEliminar
  4. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  5. In the last picture, after adding library project, DO NOT forget to press 'Apply' button. Otherwise the green tick would be changed to red error sign.

    ResponderEliminar
    Respuestas
    1. i've pressed the apply button, but i still get the red error sign. do you know why?

      Eliminar
  6. So where is the 2nd part of this?

    ResponderEliminar
  7. Right here: http://tolkianaa.blogspot.com/2012/04/how-to-use-android-wheel-part-ii.html

    ResponderEliminar
  8. i got error on wheel_demo (wheel.jar missing in wheel bin)...

    ResponderEliminar
  9. i tried to add wheel to the library, i already clicked apply then OK.
    but when a check the properties again, the green tick had changed to red error sign.
    do u know why?
    THANKS :)

    ResponderEliminar
  10. Because your SDK and project are not in same physical folder on hard disk, remember that the project and library must be in same disk partition phisically.

    ResponderEliminar
  11. u have all just to check your project build target on properties

    ResponderEliminar
  12. I have an sample app that has four spinning wheels with date, hour, minute and am(or pm). and i got d values (hour, minutes & am(or pm)) but i have one problem of getting days value because in my case did not get proper position so, please
    can anyone tell me, How can i get proper values from these wheels ? please see my below code.

    private class DayArrayAdapter extends AbstractWheelTextAdapter {
    private final int daysCount = 365;
    @SuppressWarnings("unused")
    int index_item = 0;
    int day = 0;
    Calendar calendar;

    protected DayArrayAdapter(Context context, Calendar calendar) {
    super(context, R.layout.day, NO_RESOURCE);
    this.calendar = calendar;
    setItemTextResource(R.id.monthday);
    data = new ArrayList();
    }

    public int getItemId(int arg0) {
    return arg0;
    }

    public View getItem(int index, View cachedView, ViewGroup parent) {
    //int day = -daysCount / 2 + index;
    this.index_item = index;
    day = index;
    Calendar newCalendar = (Calendar) calendar.clone();
    newCalendar.roll(Calendar.DAY_OF_YEAR, day);
    View view = super.getItem(index, cachedView, parent);
    weekday = (TextView) view.findViewById(R.id.weekday);
    if (day == 0) {
    weekday.setText("");
    } else {
    DateFormat format = new SimpleDateFormat("EEE");
    weekday.setText(format.format(newCalendar.getTime()));
    }

    monthday = (TextView) view.findViewById(R.id.monthday);
    if (day == 0) {
    monthday.setText("Today");
    monthday.setTextColor(0xFF0000F0);

    } else {
    DateFormat format = new SimpleDateFormat("MMM d");
    monthday.setText(format.format(newCalendar.getTime()));
    monthday.setTextColor(0xFF111111);

    data.add(format.format(newCalendar.getTime()));

    }
    return view;
    }

    public ArrayList getText() {
    return data;
    }

    public int getItemsCount() {
    return daysCount + 1;
    }

    protected CharSequence getItemText(int index) {
    return "";
    }
    }

    ResponderEliminar
  13. Este comentario ha sido eliminado por un administrador del blog.

    ResponderEliminar
  14. Este comentario ha sido eliminado por un administrador del blog.

    ResponderEliminar
  15. How can I use this library in my android studio project?

    ResponderEliminar
    Respuestas
    1. Please take a look at the new article (http://tolkianaa.blogspot.com/2016/01/how-to-use-android-wheel-v2-android.html) which show's how to integrate this library with Android Studio & Gradle.

      Eliminar