Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level2 wheel not update when Level1 wheel issue change event #2

Closed
GoogleCodeExporter opened this issue Feb 25, 2016 · 2 comments
Closed

Comments

@GoogleCodeExporter
Copy link

Dear sir, first.thanks for your great work .I get a issue to report,maybe it 
can make this view more helpful.

What steps will reproduce the problem?
1. setup two wheel view called level1 and level2
2. setup a change listener to level1,update the level2's adapter in the 
listener's method
3. scroll up and down of level1 wheel, level2 not update (repaint)

What is the expected output? What do you see instead?

  It should update the level2 wheel.


Code likes below:

                this.level1ItemWheel = (WheelView) findViewById(R.id.level1Item);
        this.level2ItemWheel = (WheelView) findViewById(R.id.level2Item);

                level1ItemWheel.setAdapter(new ArrayWheelAdapter<String>(
                    new String[]{"level1A","level1B"}));

            level1ItemWheel.setVisibleItems(5);
            level1ItemWheel.setCurrentItem(0);


            level2ItemWheel.setAdapter(new ArrayWheelAdapter<String>(
                    new String["child1_of_level1A","child2_of_level1A"]));

        level2ItemWheel.setVisibleItems(5);
        level2ItemWheel.setCurrentItem(0);


                level1ItemWheel.addChangingListener(new OnWheelChangedListener(){
                        public void onChanged(WheelView wheel, int oldValue, int newValue) {
            if (wheel == level1ItemWheel && newValue==1) { //when scroll to levelB,change it's child list.

                String level1Item = wheel.getAdapter().getItem(newValue);

                                //not working!!!!!!!!!!!!!!!!here
                level2ItemWheel.setAdapter(new ArrayWheelAdapter<String>( new String[]{"child1_of_level1B"} ));


                level2ItemWheel.setVisibleItems(5);
                level2ItemWheel.setCurrentItem(0);



                return;
            }  
                   );


How to fix it:
I found that setCurrentItem of WheelView ,check the select index before 
invalidate the ui.

    public void setCurrentItem(int index, boolean forceInvalidate) {

        if (index != currentItem) {
            invalidateLayouts();

            int old = currentItem;
            currentItem = index;

            notifyChangingListeners(old, currentItem);

            invalidate();
        }

    }


This may cause the second wheel not update view in this situation. I overload a 
new method:

public void setCurrentItem(int index, boolean forceInvalidate) {

        if (forceInvalidate || index != currentItem) { //use can choose weather he want to update the ui to new adapter here
            invalidateLayouts();

            int old = currentItem;
            currentItem = index;

            notifyChangingListeners(old, currentItem);

            invalidate();
        }

    }


And modify the code line in the change listener:

level2ItemWheel.setAdapter(new ArrayWheelAdapter<String>( new 
String[]{"child1_of_level1B"} ));

level2ItemWheel.setVisibleItems(5);
level2ItemWheel.setCurrentItem(0,true);///And now it can work now!!!


Hope this can help....







Original issue reported on code.google.com by yongxin...@gmail.com on 31 Oct 2010 at 12:06

@GoogleCodeExporter
Copy link
Author

Thank you for the issue.

I think the problem is in WheelView.setAdapter() - it should also invalidate 
layouts (set them to null by calling invalidateLayouts(), like setCurrentItem() 
does).

But you solution has a one good thing - I think there should be also a public 
method for invalidating wheel control in any way.

Thanks you very much!
I will update sources soon.

Original comment by yuri.kan...@gmail.com on 31 Oct 2010 at 7:25

@GoogleCodeExporter
Copy link
Author

Original comment by yuri.kan...@gmail.com on 3 Nov 2010 at 7:57

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant