Thursday, January 27, 2011

Android wheel update: custom views for items

I'm glad to inform you about updating the wheel control. There has been implemented the main feature for this widget - the ability for using  custom views for wheel items, like in the ListView control.


Now it is possible to show anything in the wheel, as simple text items

... as images

Looks nice :)

How to use
For simple text items there can be used ArrayWheelAdapter and ArrayWheelAdapter adapters, like before. They work also with user defined layouts for items and the wheel label.
For complex wheel items there should be used user defined adapters by implementing the WheelViewAdapter interface. For text based adapters there can be used the AbstractWheelAdapter class as a base.

Constraints

All wheel items should have the same height to be corrected rendered. The label height should be less than the height of wheel item.
The label width should not be so big since items are show in the rest area.


Backward compatibility
All application using the wheel should work with new adapters, but with small fix: ArrayWheelAdapter and ArrayWheelAdapter adapters have been moved to the kankan.wheel.widget.adapters package.
The old WheelAdapter interface has been set as deprecated and will be removed in next builds, with  corresponding WheelView methods. There should be used the WheelViewAdapter interface instead.

124 comments:

  1. Wow ... simply awesome!! Thanks

    ReplyDelete
  2. I am unable to get to the link on Google Code website. Has it been taken down?

    ReplyDelete
  3. Great but, setLabel method has disappeared?

    ReplyDelete
  4. Yes, I decided to remove label from the wheel since is it some difficult for maintaining. May be it will be added again in the future.

    ReplyDelete
    Replies
    1. I would like to use the setLabel method, it makes the work easy when we just have to put one label. When will this great feature be retained back?

      Delete
  5. Hi. I would like to include Android wheel in my app. However, my app is not open source, but is sold as a paid app at Android Market. Am I allowed to include your lib in my app provided the author name and a link to the Apache licence is included and visible to the user? Thanks.

    ReplyDelete
  6. Thomas,

    No problem, just mention the android wheel project name, my name and the Apache license link.

    ReplyDelete
  7. Very cool! I will use this in a project! Thanks for sharing!

    ReplyDelete
  8. this is cool stuff .
    I was just wondering, like the password example, if I have a edit field and when I click the edit field the scrolls should be displayed instead of softkeypad?

    ReplyDelete
  9. Anonymous,
    If I understand correctly you are talking about using an edit field as a wheel item.
    In this case it is impossible edit data since the wheel just shows it and doesn't allow any actions with items.

    ReplyDelete
  10. thanks KanKan for reply.
    Actually what I said is ....
    If in a layout, I have an edit field now I want to enter some number data in that field.
    Normally when we click edit field SoftKay pad appears and we enter data.

    I want when I click edit field, your scroll wheels with numbers should appear dynamically and I just scroll the numbers as desired and select number lets say 1234.
    Then 1234 will be in the edit field.

    sorry for the long post:)

    ReplyDelete
  11. Hi Yuri,

    The app seems amazing!!!
    I'm straight away planning to include the app in my application but before that i have few queries regarding its legalized usage.

    1) Is there any pattern applied by Apple which can restrict me from using the Wheel GUI? I heard there was one regarding usage of Album pattern GUI in apple’s Music Player.
    2) Where exactly I have to include project name, yourname & apache license link? I wonder if I include it in my java file’s javadoc, how end-user are going to see it?

    Hope you can best answer these queries so I can straight away refer to your project library?
    Thanks, thanks a lot. :)

    ReplyDelete
  12. Hi ABhi,

    1) I don't know about any restriction from Apple. But in any case you can "tune" the wheel to have another backgrounds, middle area etc, like HTC date/time wheels.
    2) If you are going to open your sources it is enough to do that on code. Otherwise you can add these items to the about screen of your app, like some people did.

    ReplyDelete
  13. Hi Kankan,
    Thanks for the reply :)
    But i'm bouncing back here with further doubt.
    1) That'll do. Thanks again.
    2) The code is not open source so no point in including in java. Regarding using about screen, the problem is that this one is not any commercial application & customer is one the reputed firm (say nike, adidas) which won't allow me to include anything in 'about' screen.
    :( Looks like i'm stuck, please help!!

    ReplyDelete
  14. Hi ABhi,

    Could you please read http://www.apache.org/licenses/LICENSE-2.0.html and if your intentions meet the Apache license requirements you can use it w/o any limitations.

    ReplyDelete
  15. Is it possible to get the click event on the views composing the item's custom layout?

    for example: getting the click event onto the flag ImageView in the cities wheel (from your demo project)

    I tried to set focusable on views but the event is not raised

    ReplyDelete
  16. Hi kanKan,
    Excellent Control, Hats off...
    having slight issue with ellipsizing(truncating at end) the textview... tried to set it in the adapter where size,color are set.. works on small width Wheels , not bigger .. a little hint :)
    Thanks...

    ReplyDelete
  17. Your wheel view is great. It was easy to integrate as well.

    The one thing I'm not sure is how to add extra text to the current value - such as the 'Today' in the second picture above, or in the old 'NumericView' posts that show 'hour' 'min' units only on the current value. That was done with the 'setCaption(...)' call I think. Is there a current alternative?

    Thanks for publishing the great project.

    ReplyDelete
  18. Kevin,

    It is possible to use labels, but outside of wheel.
    You can create a linear layout, add a wheel and a text view, and center them. The one more thing is to make them together to look like the wheel. Just use a custom layout based on the linear one, and override the dispatchDraw() and move all wheel background painting code there.
    void dispatchDraw(...)
    {
    // 1. draw the wheel bg, or just set the bg for this layout
    // 2. call the base dispatchDraw() to draw the wheel and label
    // 3. draw the wheel shadows if necessary
    // 4. draw the center rectangle over the wheel current item and the text label
    }

    Hope it helps.
    BTW I'm going to add it to the wheel demo.

    ReplyDelete
  19. Hi Yuri,

    First of all thanks you for sharing this great wheel with the world.

    I've made a app with your library in it. I would like to put my app on the android market sometime soon.

    This would be my first app on the market and would like to be sure that I don't do anything against some rules.

    It will be a free app with only an ad bar at the bottom of the screen. In the about screen I've wrote the following text: "This projects makes use of the 'Android Wheel' created by Yuri Kankan and is licensed under the Apache License (http://www.apache.org/licenses/LICENSE-2.0.html)"

    Is this enough to use your library in my project?

    Thanks a lot for your reply!

    Kind regards,
    Patrick

    ReplyDelete
  20. Hi Patrick,

    Sure, it's enough.
    Thank you for choosing the wheel project!

    --
    Yuri

    ReplyDelete
  21. Hi kankan,

    Great product and thanks for sharing.

    One quick question, how do I set the font size for the labels in the wheel? Your demo runs perfectly on my environment. But when I include your library, the font is huge and I didn't change anything. Any suggestion?

    Thanks.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. Hi
    At first thanks for your valuable code.I use your code.But I have use year month and date in a same wheel .I set a image for a date .when change date the image will change.show image from database for the date .when date change the image also change.How can is this possible.Can you give some example or Hint.

    Thanks and Regards,
    Md Maidul Islam

    ReplyDelete
  24. Hi kankan,

    Great product and thanks for sharing.

    One quick question, how do I set the font size for the labels in the wheel? Your demo runs perfectly on my environment. But when I include your library, the font is huge and I didn't change anything. Any suggestion?

    Thanks.

    ReplyDelete
  25. Hi Maidul,

    You should use wheel event listeners in this case.

    ReplyDelete
  26. Mark S,

    I have no idea :(
    Please look at the wheel item XML and adapters.
    If I had a chance to reproduce this issue I would help you.

    ReplyDelete
  27. Thanks Kankan. I'll give it a try.

    ReplyDelete
  28. Hi Yuri,

    I've just released version 1 of my application (https://market.android.com/details?id=com.trickydesign.moneyistime).

    I couldn't get the interface this way without your libraries and help.

    Thanks a lot!

    Kind regards,
    Patrick

    ReplyDelete
  29. Hi Thanks for this can you post all code coz i am not able to do same thing in my project.
    Thanks in advance.

    ReplyDelete
  30. Hi Patrick,

    I don't believe that it is my wheel :)
    It looks so nice.
    Thank you for this very useful app, I used to use a unit converter for the time-money measuring that was not comfortably.

    ReplyDelete
  31. Looking for somebody that can implement this http://itunes.apple.com/qa/app/screw-information-database/id369825047?mt=8 I have database all ready made in sqlite or xml anybody interested email me at catalanopinto@gmail.com

    ReplyDelete
  32. Hi Yuri,

    I'm currently working on a update of my Money is Time App, but I can't get what I would like.

    I would like to the following, when switching from portrait to landscape to update the minwidth and textsize.

    I use this function to init the wheel:
    private void initWheel(int id, int min, int max, String format, int width, int text_size) {
    WheelView wheel = getWheel(id);
    NumericWheelAdapter adapter = new NumericWheelAdapter(this, min, max, format);
    wheel.setViewAdapter(adapter);
    wheel.setCurrentItem(0);
    wheel.setMinimumWidth(width);
    adapter.setTextColor(0xFFFFFFFF);
    adapter.setTextSize(text_size);
    wheel.setCyclic(true);
    wheel.setInterpolator(new AnticipateOvershootInterpolator());
    wheel.addScrollingListener(scrolledListener);
    }

    I've tried this, but this didn't work:
    public void set_gui_portrait() {
    setContentView(R.layout.main);
    WheelView wheel = getWheel(R.id.money1);
    NumericWheelAdapter adapter = new NumericWheelAdapter(this);
    wheel.setViewAdapter(adapter);
    adapter.setTextSize(35);
    wheel.setMinimumWidth(50);
    }

    I've tried some other things, but all didn't do what I was looking for.

    Is there a way to do this?

    Thanks for your help!

    Kind regards,
    Patrick

    ReplyDelete
  33. Hi Yuri,

    thank you for a great project!
    Just a quick question. Is there any possibility to make the values repeat - so that as soon as the maxValue is reached the wheel continues with the minValue again?

    Example:
    minValue:0
    maxValue:3
    (0,1,2,3,0,1,2,3,0,....)

    Thanks for any kind of response!
    Best of luck and keep up the good work.
    Bruiser

    ReplyDelete
  34. ok. my bad! thanks anyway.
    setCyclic(true);
    :)

    ReplyDelete
  35. Hi Patrick,

    You are working with pixels from code, so it would be better to use dp and convert them to px.

    I suppose it would be better to use custom adapter with different layouts for landscape/portrait modes.

    ReplyDelete
  36. Hey Yuri, could you please refactor your code so that it can be used without throwing all the these raw type warnings. I do not mean to surpress them but to make the code work without actually using any sort of raw types. IMHO this is an absolute must if you are serious about your project.

    Thanks a lot. And best wishes.
    Mira Fayless

    ReplyDelete
  37. thanks! great widget! keep up the awesome work!

    ReplyDelete
  38. Hi Yuri,
    I'm trying to put a fairly complex layout (with two buttons) in each view. So far this looks great, but I'm getting no luck getting any click events. Can you shed any light on this situation?
    I know that the onTouchEvent is probably not affecting this (as I commented it and there was no change. I also get an onClick event when I put the listener on the wheel from the outside.. hmm, maybe I should put the listeners on the view items when I call getView()...

    ReplyDelete
  39. Ok, I think I sorted it out (mostly). The main reason that child views aren't getting motion events is because they aren't part of the view hierarchy.
    So what I do is call dispatchMotionEvent manually at the appropriate time.
    I'm still a little stuck, as I can't set a motion target. However, this isn't too much of a problem since I only need one down event - I can then let the main WheelView object take the rest of the events.
    If you have any better ideas, it'd be great to know.
    What would be great would be integration of your itemsLayout LinearLayout into the WheelView itself - as a child. This would allow seamless MotionEvent passing. Casp.

    ReplyDelete
  40. Oh and thanks for all the work you've put into this project - it's a great widget.

    ReplyDelete
  41. This comment has been removed by the author.

    ReplyDelete
  42. Kankan, thanks for the great wheel control. Is it possible to use the wheel in a horizontal mode? if yes then how? Thanks.

    ReplyDelete
  43. Hi .. Thank you man this is a great wheel ..

    but I am trying to make the wheel save its state .. I am useng strings name and num .. when user pick the "name" and "num" I whant it to save it and if he gets out and gets in again .. the wheel shows him what he picked .. I need your help I am new to android dev .. thank you very much

    ReplyDelete
  44. Great product and thanks for sharing,but the link ( for svn checkout ) seems unreachable^^"

    ReplyDelete
  45. Hi Yuri,

    I tried searching your blog and stackoverflow for any tips how to implement your wheel. Tried linking your source code to my project, tried including JAR that I made exporting the wheel code and still when I try to do the same/similar XML as ones in wheeldemo it doesn't work. Read on include and merge but still have problems, got any pointers for me?
    Thank you!
    Razmo

    ReplyDelete
  46. Thanks yuri,
    is there any way to control the overshoot?

    ReplyDelete
  47. Thanks for sharing. You are so Great!

    ReplyDelete
  48. Thank you for your product ! I have a question : is it possible to display a selected item in an editText? (for the country exemple with adapters). Thank you in advance.

    ReplyDelete
  49. I have the same problem as an earlier poster. I've downloaded from SVN and added the wheel to an Eclipse project, but it always displays an weird background, which seems to be the first image it encountered in alphabetical order. That is, if you change the name of the images, it shows the first one it finds in the drawable list (and it changes if you rebuild them). I got it to look sensible by creating a file 100x100 pixels of white, called "aaaaa_white.png"

    It shows the exact same thing when in the design mode of Eclipse.

    ReplyDelete
  50. Note to the above: I am using two Android libraries, as I'm using another variant of my app to provide some Activity classes. I don't know if that makes a difference. I tried changing the order of the libraries in the project, but it doesn't make any difference.

    I wonder if it's an issue of R.java, or whether the WheelView isn't painting the canvas sensibly and assumes it can use the first index in an array.

    ReplyDelete
  51. Hi:

    Thanks for sharing. I really appreciate it.

    As my contribution, I have created a class which fix a small bug. When the user is scrolling and the setCurrentItem is called, sometimes it cannot set it in proper way. Here is my code to do it using countDown.

    //sometime, when it is scrolling, the set method is not accurate
    //Start a timer (scroll duration = 400ms). After it, check it again.
    CheckWheelsCountDown checkWheelsCountDown = new CheckWheelsCountDown(4000, 500,
    actualScheduledHours,
    actualScheduledMinutes,
    actualScheduledSeconds);
    checkWheelsCountDown.start();


    public class CheckWheelsCountDown extends CountDownTimer {
    private boolean hoursCorrect = false;
    private boolean minutesCorrect = false;
    private boolean secondsCorrect = false;

    private int actualScheduledHours = 0;
    private int actualScheduledMinutes = 0;
    private int actualScheduledSeconds = 0;

    private int actualWheelHours = 0;
    private int actualWheelMinutes = 0;
    private int actualWheelSeconds = 0;

    public CheckWheelsCountDown(long millisInFuture, long countDownInterval, int actualScheduledHours,
    int actualScheduledMinutes,
    int actualScheduledSeconds) {
    super(millisInFuture, countDownInterval);
    this.actualScheduledHours = actualScheduledHours;
    this.actualScheduledMinutes = actualScheduledMinutes;
    this.actualScheduledSeconds = actualScheduledSeconds;
    }

    @Override
    public void onFinish() {
    Log.i(LOG_TAG, "finished");
    checkWheel();
    }

    @Override
    public void onTick(long millisUntilFinished) {
    Log.i(LOG_TAG, "tick");
    checkWheel();
    }

    private void checkWheel(){
    Log.i(LOG_TAG, "Checking wheels");
    if (!hoursCorrect) {
    actualWheelHours = hoursWheel.getCurrentItem();
    if (actualWheelHours != actualScheduledHours) {
    Log.v(LOG_TAG, "The hours is not right " + actualWheelHours);
    hoursWheel.setCurrentItem(actualScheduledHours, true);
    } else {
    hoursCorrect = true;
    Log.v(LOG_TAG, "Hours correct");
    }
    }

    if (!minutesCorrect) {
    actualWheelMinutes = minutesWheel.getCurrentItem();
    if (actualWheelMinutes != actualScheduledMinutes) {
    Log.v(LOG_TAG, "The minutes is not right " + actualWheelMinutes);
    minutesWheel.setCurrentItem(actualScheduledMinutes, true);
    } else {
    minutesCorrect = true;
    Log.v(LOG_TAG, "Minutes correct");
    }
    }

    if (!secondsCorrect) {
    actualWheelSeconds = secondsWheel.getCurrentItem();
    if (actualWheelSeconds != actualScheduledSeconds) {
    Log.v(LOG_TAG, "The seconds is not right " + actualWheelSeconds);
    secondsWheel.setCurrentItem(actualScheduledSeconds, true);
    } else {
    secondsCorrect= true;
    Log.v(LOG_TAG, "Seconds correct");
    }
    }
    }
    }

    ReplyDelete
  52. Hi,

    I the Time2Activity i am not able to get the correct selected item,When i call getCurrentItem on day_wheel, it is returning value which is 2 days ahead of selected value.

    ReplyDelete
  53. Hi, i'm using your wheelview as a replacment for the boring Numberpicker. and it really works great.
    But in some cases I would need a horizontal wheelview, so if you are looking for new features to add to the whellview and optinoal orientation property would be really cool. And probably something even apple hasn't (no sure on that ;-)

    ReplyDelete
  54. Hi, I'm having trouble getting the wheel to work in a dialog, can anyone point to an example where it is used, thanks

    ReplyDelete
  55. Yuri,
    Awesome work. Thank you.

    What/where should be changed so minutes (as example) on the time wheel, would show only numbers 00, 15, 30, 45 rather than all numbers 00 to 59 ?

    Thanks,
    Ahmad

    ReplyDelete
  56. Hi,

    Great work guys !!! Thanks a lot...

    I tried to implement marquee in the textview that you have used in AbstractWheelTextAdapter class... But it fails.. i think the textview does not get the focus... can u help me in this??

    Thanks,
    Vivek

    ReplyDelete
  57. This wheel widget is fantastic. Thanks a lot for such a great free component. It's the best replacement I found for the stock time picker. I've used it in my (free & open source) android app (RC Flight Timer and Logger).

    Many many thanks,
    GiD

    ReplyDelete
  58. Really nice stuff. I am going to use it as a date picker, and looked at the demo date picker.
    There is a small error in the code, causing February to have 31 days. In DateActivity updateDays should look like this:

    void updateDays(final WheelView year, final WheelView month, final WheelView day) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem());
    calendar.set(Calendar.MONTH, month.getCurrentItem());
    calendar.set(Calendar.DAY_OF_MONTH, 1); // Added
    calendar.getTime(); // Added
    int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    day.setViewAdapter(new DateNumericAdapter(this, 1, maxDays, calendar.get(Calendar.DAY_OF_MONTH) - 1));
    int curDay = Math.min(maxDays, day.getCurrentItem() + 1);
    day.setCurrentItem(curDay - 1, true);
    }

    Best regards,
    Stefan

    ReplyDelete
  59. YOU ARE AWESOME
    I'll remember your name Yuri

    Best regards from Poland to Ukraine

    ReplyDelete
  60. This comment has been removed by the author.

    ReplyDelete
  61. Hi Yuri, I am using your wheel source code for my application requirement, but am facing a problem while debuging. As I am new to android, I was unable to find the problem. The error is "CachingStrategy cannot be resolved". Please help how to debug this error.

    ReplyDelete
  62. Hi Yuri, I solved my above query and now am getting some more problems in WheelView.java file.
    There in rebuildLabel() method, you have a statement labelView=viewAdapter.getLabelItem(label,cache.getCachedLabelView() which is not defined in the WheelViewAdapter interface.

    The second error I got is in the getItemView() method, where you called getEmptyItem() method defined in WheelViewAdapter interface with one argument but the actual method definition in the adapter contains 2 parameters.

    The third problem is similar to the second problem with the method getItem() called in the getItemView() method of WheelView class.

    Please help me to solve these bugs.

    thanks in advance.

    ReplyDelete
  63. Chandra,

    Please check your sources. WheelView does not have rebuildLabel(), and getEmptyItem() is called with 2 arguments.

    ReplyDelete
  64. Great Work! I am using it in my app to select the month and the day of month (side by side, like in the countries/cities demo) WITHOUT selecting a year. All other date pickers require the selection of a year, which renders them useless for me. Your wheel was exactly what I was looking for.
    However, I am having one issue:
    On screen rotation, I usually use onSaveInstanceState/onRestoreInstancState to preserve state of the activity. With the wheel this does not seem to work.
    Am I missing something? Will this be fixed in future releases?

    ReplyDelete
  65. Dear Kankan,

    First of all, Thanks a lot for great work and sharing it here. I'm trying to use the city list wheel for one of my requirement. But I have the data in Data Base (SQLite) of my app. Please help me to bind this data to these wheels. I have used Cursor Adapters and have good knowledge on it. Please help me.

    Thanks & Regards,
    Durga.

    ReplyDelete
  66. Really good control, thanks. I have modified the source slightly to include support for stepped numeric wheels, for instance if you want 0 ... 5 ... 10 ... 15 ... 20 etc. instead of 1...2...3...4. Happy to send a patch if you tell me how you want it..?

    ReplyDelete
    Replies
    1. Hi Stephen! From where did you get the code?

      Delete
  67. Hi! It's a neat application. Is it possible to get the code? manauregarcia@gmail.com

    ReplyDelete
  68. hi........ can you tell me how to set an image or custom wheel in wheel view..

    ReplyDelete
  69. Hi, first off, great widget!

    I'm curious though, is there any way to apply a custom font to one? I've got a ttf file in assets/raw, and I can apply it to other objects, but I'm not too sure where to start with applying it to a wheel. Any help would be appreciated!

    ReplyDelete
  70. Hi i need your help
    i am used WheelController. now i will to scroll up to one down to currentittem or to up one currentitem.

    i had modify the methode onTouch in WheelScroller.

    public boolean onTouchEvent(MotionEvent event, int currentItem) {
    switch (event.getAction()) {

    case MotionEvent.ACTION_UP:
    lastTouchedY = event.getY();
    listener.onScroll(-1);
    scroller.forceFinished(true);
    lastTouchedY = event.getY();
    clearMessages();
    break;
    case MotionEvent.ACTION_DOWN:
    lastTouchedY = event.getY();
    listener.onScroll(1);
    scroller.forceFinished(true);
    lastTouchedY = event.getY();
    clearMessages();
    break;

    case MotionEvent.ACTION_MOVE:
    // // perform scrolling
    Log.i("event.getY()", ""+event.getY());
    Log.i("lastTouchedY", ""+lastTouchedY);
    int distanceY = (int)(event.getY() - lastTouchedY);
    Log.i("distanceY", ""+distanceY);
    if (distanceY > 0 ) {
    startScrolling();
    listener.onScroll(1);
    scroller.forceFinished(true);
    lastTouchedY = event.getY();
    }

    if (distanceY <0 ) {
    startScrolling();
    listener.onScroll(-1);
    lastTouchedY = event.getY();
    scroller.forceFinished(true);
    }
    break;
    }
    //
    if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
    justify();
    }


    return true;
    }
    }
    but no effect

    ReplyDelete
  71. Hi
    How do I resize the layout to fit any resolution?

    ReplyDelete
  72. I'm having trouble getting the widget to work. Do you have any usage examples?

    ReplyDelete
  73. Hi Yuri, This looks exactly what I was looking of to implement in my application. Could you please explain how I can get hold of the source code so I can implement the rollers in my project. Sorry for the newbie question but im new to android programming.

    ReplyDelete
    Replies
    1. I have tried downloading the read-only code using svn but I get error source not found when I do so....

      Delete
    2. Hey,

      the folder "android-wheel-read-only" doesn't exist in the repository anymore. Instead download the whole trunk. In there is the project library as well as a demo project for refrence

      (svn checkout http://android-wheel.googlecode.com/svn/trunk/)


      @Kankan: Thanks a lot for the great work!

      Delete
    3. Thanks for the update Ir Relevant. @KanKan perhaps the source downloads page should be updated to show that the read-only project no longer exists? P.S great work looks excellent.

      Delete
    4. Hi Iain,

      It is a standard Google code page and I'm unable to change it :)

      Actually it shows the whole SVN command line to get the code:
      svn checkout http://android-wheel.googlecode.com/svn/trunk/ android-wheel-read-only
      where "http://android-wheel.googlecode.com/svn/trunk/" is the project repository and "android-wheel-read-only" is just your local source folder.
      So, everything is correct :)

      Delete
    5. @KanKan Im a novice at android so its all quite new to me :D By the way did you see my post below? I seem to be having some issues and wondered if you had some time to look at my set up? I know your probably busy with your own work but a little help to get started would be greatly appreiciated

      Delete
  74. Can someone explain how to get the code to work?
    I have tried adding the projects into my workspace folder but when I try to view the XML for the layouts I get Errors in the Workspace Log.

    For example when I look at the time2_layout.xml file in the wheel-demo i get the following error in the workspace log:

    null
    Error
    Wed Jun 20 11:37:09 BST 2012
    time2_layout.xml: Could not resolve resource value: 0x7F020009.

    android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F020009.
    at com.android.layoutlib.bridge.android.BridgeResources.throwException(BridgeResources.java:648)
    at com.android.layoutlib.bridge.android.BridgeResources.getDrawable(BridgeResources.java:171)
    at kankan.wheel.widget.WheelView.initResourcesIfNecessary(WheelView.java:427)
    at kankan.wheel.widget.WheelView.calculateLayoutWidth(WheelView.java:482)
    at kankan.wheel.widget.WheelView.onMeasure(WheelView.java:518)
    ......
    I truncated the log as it wouldn't fit in the available text size for comments.

    Anyone else had this problem? If so could you provide a solution?

    Thanks

    ReplyDelete
    Replies
    1. I suppose it is a common issue for the wheel control, since it was not developed to be viewable on the eclipse layout editor.
      The main way is to use XML layout editor.

      I had plans to fix that, but I don't know when it will be done.

      Delete
    2. @Kankan I have tried to implement the Date example in my own application but get the following error when I launch my date picker activity:

      06-20 16:10:20.604: E/AndroidRuntime(560): FATAL EXCEPTION: main
      06-20 16:10:20.604: E/AndroidRuntime(560): java.lang.NoClassDefFoundError: kankan.wheel.R$drawable
      06-20 16:10:20.604: E/AndroidRuntime(560): at kankan.wheel.widget.WheelView.initResourcesIfNecessary(WheelView.java:427)
      06-20 16:10:20.604: E/AndroidRuntime(560): at kankan.wheel.widget.WheelView.calculateLayoutWidth(WheelView.java:482)
      06-20 16:10:20.604: E/AndroidRuntime(560): at kankan.wheel.widget.WheelView.onMeasure(WheelView.java:518)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:696)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.onMeasure(LinearLayout.java:306)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.View.measure(View.java:8171)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.os.Handler.dispatchMessage(Handler.java:99)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.os.Looper.loop(Looper.java:123)
      06-20 16:10:20.604: E/AndroidRuntime(560): at android.app.ActivityThread.main(ActivityThread.java:4627)
      06-20 16:10:20.604: E/AndroidRuntime(560): at java.lang.reflect.Method.invokeNative(Native Method)
      06-20 16:10:20.604: E/AndroidRuntime(560): at java.lang.reflect.Method.invoke(Method.java:521)
      06-20 16:10:20.604: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
      06-20 16:10:20.604: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
      06-20 16:10:20.604: E/AndroidRuntime(560): at dalvik.system.NativeStart.main(Native Method)

      Any ideas what I'm doing wrong? I have added the Wheel.jar file to my libs folder and everything seems to be able to find the references but i still get this error.

      Delete
    3. I needed to make these few changes to have it work in the Eclipse Layout editor.
      Added 'isInEditMode()'

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      if (this.isInEditMode()) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      initResourcesIfNecessary();
      return;
      }
      ...


      protected void onLayout(boolean changed, int l, int t, int r, int b) {
      if (this.isInEditMode()) {
      super.onLayout(changed, l, t, r, b);
      return;
      }
      ...

      protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      if (this.isInEditMode()) {
      return;
      }
      ...

      Delete
    4. small changes and it is much better with eclipse layout editor. (not perfect but usable)

      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      if (this.isInEditMode()) {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      if (centerDrawable == null) {
      centerDrawable = getContext().getResources().getDrawable(R.drawable.wheel_val);
      setBackgroundResource(R.drawable.wheel_bg);
      }
      return;
      }
      ...

      protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      if (this.isInEditMode()) {
      drawCenterRect(canvas);
      return;
      }
      ...

      protected void onLayout(boolean changed, int l, int t, int r, int b) {
      if (this.isInEditMode()) {
      super.onLayout(changed, l, t, r, b);
      return;
      }
      ...

      Delete
  75. @Kankan Hi I have managed to fix the problems I was having. I had added the projects into my workspace but not set them up as library projects. Instead I had added the wheel.jar into my libs folder.

    If anyone is having similar problems check out the link below. I found the following resource looking in StackOverFlow for reasons why I was geting the NoClassDefFoundError:

    http://tolkianaa.blogspot.mx/2012/03/do-not-try-to-reinvent-wheel.html



    Cheers Iain

    ReplyDelete
  76. @Kankan Hi This widget is totally amazing +1 to you Yuri. I have found a small issue that maybe you could help clarify. I am trying to implement a Date Time picker which needs to be able to show years in the past.

    The year wheel is set up using the following code:

    // year
    curYear = cal.get(Calendar.YEAR);
    year.setViewAdapter(new DateNumericAdapter(this, curYear, curYear + 10, 0)); // modify to show past year
    year.setCurrentItem(curYear);
    year.addChangingListener(dateListener);

    So say I want to show 10 years in the past I would modify the commented line to this:
    year.setViewAdapter(new DateNumericAdapter(this, curYear - 10, curYear + 10, 0)); // modified

    However the current item is not set correctly here. Its always the first value in the list. Any ideas why this happens? Even if I set the last parameter of the DateNumericAdapter to curYear it still shows the first value


    Cheers Iain

    ReplyDelete
  77. I am trying to make the minutes wheel stop when the minutes part of my time picker hits various values.

    For instance if the wheel spins and hits 00, 15 ,30 or 45 then it should stop and the user would then have to spin again if they want to pick a different number?

    This is standard functionality on the HTC wheel spinner.

    Any ideas how I would go about implementing this?

    ReplyDelete
  78. Very nice widget, congratulations.
    On the text wheel I'm trying to put a text that is longer then the view area. I want to show "..." when the text does not fit in the area.

    I tried it adding:
    view.setEllipsize(android.text.TextUtils.TruncateAt.END);

    To the configureTextView(TextView view) method, AbstractWheelTextAdapter class. But it is not working. Any clue?

    Thanks.

    ReplyDelete
  79. hello kankan,I want to know how to change the text size of item in the wheelview,cause the size is too big,can you give me some tips?thank you.

    ReplyDelete
    Replies
    1. okay I got it,set adapter text size.....

      Delete
  80. Hi kankan,

    Excellent widget! Unfortunately I have run into a problem! I have two android wheel instances for conversion. I want the second wheel to convert and change simultaneously when the user scrolls the first one to set the data. And this should happen vice-versa. But this results in a loop and throws a StackOverflowError. Any ideas on how I can solve this problem?

    Thanks.

    PS: You can take a look at the code here: http://stackoverflow.com/questions/11587864/android-wheel-scroll-second-wheel-when-the-first-is-scrolled

    ReplyDelete
  81. very useful app,thnks...

    ReplyDelete
  82. Hi,

    Your widget is really cool, however when I try to use the click listener, it does not work on the centered item. Works fine for the other items, but clicking on the hilighted item does not invoke a click event. Am I doing something wrong? or is there a way I can get it to work?

    Thanks.

    ReplyDelete
  83. hello,KanKan,I have a problem here.when I use this widget,The text content is too long ,and The textView must be singleLine,but when I see the widget,I find that There have left extra space for the text to fill in.so I want to know how can I let the textview fill the widget width....wait for your reply.....

    ReplyDelete
  84. Can i use the wheeler project to build my own product.

    ReplyDelete
  85. Юрий, крутейший виджет! Но есть вопрос: нет ли планов портировать его под другую среду разработки, например Appcelerator Titanium? Если вкратце, это кросплатформенный фреймворк по созданию нативных Android/iOS приложений на JavaScript. И, к сожалению, у него нет возможности создать такой контрол, но зато есть возможность использовать нативные андроидовские модули (https://wiki.appcelerator.org/display/guides/Android+Module+Development+Guide). И опять же к сожалению, моих личных познаний Java недостаточно чтобы сделать это самостоятельно... Комьюнити тебе было бы благодарно, на внутренних форумах многие ищут возможности создания подобных контролов.

    С уважением и заранее спасибо, если решишь этим заняться!

    ReplyDelete
  86. This widget is really cool!

    I have a doubt , How is it possible to lock or disable days in DayArrayAdapter? i want to hide or disable some days in a week, is it possible to do that?

    ReplyDelete
  87. Hello Yuri

    I am trying to use your Wheel widget from the Guilib project which seems to allow a horizontal orientation. However, when I specify android:orientation in the XML, the widget shows as vertical. If in the code, I use setOrientation(android.widget.LinearLayout.HORIZONTAL) I get a null pointer exception at kankan.wheel.widget.WheelRecycle.recycleItems(WheelRecycle.java:62).


    Please can you tell me what I'm doing wrong?

    Thanks

    Andrew

    ReplyDelete
  88. Hi Yuri

    Thank you for sharing your widget, it's actually what I'm looking for. I'm working on a project which wants the highlight item(center one) could change color. I mean when one item comes into center, the text color will changed at once, even only part of the text come into it(then change that part). Same when the item going out of the center line, the out part will change back to normal color at once.

    Do you have any idea on how to make this feature work?

    Thank you,

    Winkey

    ReplyDelete
  89. Hello Yuri, a wonderful wheel you made!
    Sort of newbie, I need some directions I am afraid... of actually getting the demo to run under Eclipse.
    I used svn to check it out.
    I imported the projects into Eclipse.
    Then it comes with loads of errors;
    mostly of the type: "kankan.wheel.widget.WheelView failed to instantiate".
    I must be doing something stupid.. any clues?
    Greetings from the Netherlands,
    job


    ReplyDelete
  90. Helli Yuri,

    COuld you please help me regarding DatePicker. I need to swap the Day and Month columns . please help me how to do this.

    i need MONTH | DAY | YEAR format

    ReplyDelete
  91. I have what is probably a dumb question but I am new to Android development although I have been programming for quite a while.

    I am trying to build and test the demo app and I am getting a lot of errors when building it.

    Any ideas what I am doing wrong? I have just installed the latest ADT. I am on a PC with Windows 7.

    Here is what I am seeing.

    Description Resource Path Location Type
    france cannot be resolved or is not a field CitiesActivity.java /WheelDemo/src/kankan/wheel/demo line 82 Java Problem
    canada cannot be resolved or is not a field CitiesActivity.java /WheelDemo/src/kankan/wheel/demo line 82 Java Problem
    usa cannot be resolved or is not a field CitiesActivity.java /WheelDemo/src/kankan/wheel/demo line 82 Java Problem

    id cannot be resolved or is not a field CitiesActivity.java /WheelDemo/src/kankan/wheel/demo line 27 Java Problem

    There is about 40 of these errors

    layout cannot be resolved or is not a field CitiesActivity.java /WheelDemo/src/kankan/wheel/demo line 25 Java Problem

    There is about 20 of these errors


    Ideas?

    ReplyDelete
    Replies
    1. I had the same problem and solved it by removing "kankan.wheel.R" from my imports.

      Delete
  92. Hi, I'm using your wheel project in a project of Mine, and I'm very impressed by your code and my ability to extend it to my needs. I do have a question though - I'm trying to dynamically alter the text contained within the labels, based off of user input, and I can't seem to find a way to do this. My code to do this looks like:

    ViewGroup inp_parent = (ViewGroup) input_spinner.getItemView(input_spinner.getCurrentItem());
    TextView inp_view = (TextView) inp_parent.findViewById(R.id.abbrevs_label);
    inp_view.setText(inputValue+" "+input_abbrevs[input_spinner.getCurrentItem()]);

    Note: I made getItemView public in order to try this out, I understand it's a private method in your basic code.

    Again - thanks a ton for putting this out there, a big help!

    ReplyDelete
  93. Hi,
    I want wheel item run forever no time and cycle. How to custom it?. Please help me.

    ReplyDelete
  94. I tried wheel packeage and i can't see the problem: Any file check isn't red but when i run app y eclipse show "android library project can not be launched". If i tried android whell-demo all java files is in red except WheelDemo.java.

    I use v20 packeages... any ideas please...???

    ReplyDelete
  95. Guys! Is there any way to get the selected view? If we need to modify the style of the selected item, how could we do that?

    Thanks for the great UI component.

    ReplyDelete
  96. Icsusmi I have a problem that I cant see only a black page how can I fix it

    ReplyDelete
  97. when wheel view stops it pulls nearest view to center...I want to stop it..please tell how i can achieve it

    ReplyDelete
  98. I was previously using the myWheel.setAdapter(new ArrayWheelAdapter(logoWheelList)); now i have downloaded the update version, It gives men error on myWheel.setAdapter(new ArrayWheelAdapter(logoWheelList)); context object is needed.
    Have the method name changed in updated version??
    Please Help me

    ReplyDelete
  99. Hi, Thank you for this custom Time Picker source code.
    I am developing an application for Android, I would like to use your custom time picker in my app. My question is, if i can distribute my app (as free app) with this custom time picker without any permission from apple, because I don't know if they own this time picker design ?

    Thank you for your help

    ReplyDelete
  100. Hi kankan, first of all u did a great work. My doubt is i have implemented this for alarm manager, i have two buttons with set and cancel!!if we press set button its must show the values in textview!!

    ReplyDelete
  101. Hi..
    I m very new to this android developing..
    i saw your wheel demo and exited to do with some images.. but i dnt knw how to start with your code..
    is their any jar file to place in lib folder? Can anyone help me out here..
    Thank you

    ReplyDelete
  102. Hi Bro I am new in development i want to use this widget any body can tell me configuration settings and all steps.

    ReplyDelete
  103. on DateTimePicker :

    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 "";
    }
    }

    ReplyDelete
  104. how to change the color or zoom the selected value in wheel ?

    ReplyDelete
  105. Hi everyone

    What a fantastic project! I'm attempting to use the wheel in a slot machine application and to have the wheel spinning for a number of seconds. I am starting at position 0 and scrolling it to the last item in a loop. The problem I am having is that when it scrolls to the last item it slows down before it selects it. I would like to keep a constant speed through the whole spin. Anybody able to help me?

    Thanks

    Rich

    ReplyDelete