Android wheel scroll second wheel when the first is scrolled
<p>I am developing a converter and I have two android wheel instances for that purpose. When the user scrolls one wheel, the second wheel should automatically calculate and change the second wheel's data to that result. And this should happen vice-versa. </p>

<p>The problem with this is that the logic is cyclic as when the wheel is being scrolled and changed, the scrolled listener and changed listener is being invoked every time and this is causing StackOverFlowError.</p>

<p>How can I get the second wheel to convert and set the date when the user scrolls the first one? And vice-versa.</p>

<p>Code:</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {

   ......


   changedlistener = new OnWheelChangedListener() {
       public void onChanged(WheelView wheel, int oldValue, int newValue) {

         if (wheel.getId() == R.id.month || wheel.getId() == R.id.day || wheel.getId() == R.id.year) {
                 updateDays(year, month, day);
         } else if (wheel.getId() == R.id.hijrimonth || wheel.getId() == R.id.hijriday || wheel.getId() == R.id.hijriyear) {
                 hijriDays(hijriyear, hijrimonth, hijriday);
         }


       }
   };

   .....scrolledlistener event......

   // month

   month.addChangingListener(changedlistener);
   month.addScrollingListener(scrolledlistener);

   // year
   year.addChangingListener(changedlistener);
   year.addScrollingListener(scrolledlistener);


   //day
   day.addChangingListener(changedlistener);
   day.addScrollingListener(scrolledlistener);

   hijrimonth.addChangingListener(changedlistener);
   hijrimonth.addScrollingListener(scrolledlistener);

   hijriyear.addChangingListener(changedlistener);
   hijriyear.addScrollingListener(scrolledlistener);

   hijriday.addChangingListener(changedlistener);
   hijriday.addScrollingListener(scrolledlistener);

}

/**
* Updates day wheel. Sets max days according to selected month and year
*/
void updateDays(WheelView year, WheelView month, WheelView day) {
   Calendar calendar = Calendar.getInstance();
   calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) + year.getCurrentItem());
   calendar.set(Calendar.MONTH, month.getCurrentItem());

   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);
   int curYear = calendar.get(Calendar.YEAR);
   year.setCurrentItem(curYear);
   text.setText( (day.getCurrentItem()+1) + " " + getMonthAsString(month.getCurrentItem()) + " "  +year.getCurrentItem() );
   //setHijri(year.getCurrentItem(), month.getCurrentItem(), day.getCurrentItem());
} 

void hijriDays(WheelView year, WheelView month, WheelView day) {

   hijritext.setText((day.getCurrentItem()+1) + " " + hijri.getHijriMonthName(month.getCurrentItem()+1) + " "  + year.getCurrentItem());
   setGreg(year.getCurrentItem(), month.getCurrentItem(), day.getCurrentItem());
} 

public void setGreg(int y, int m, int d) {
    hdate = hijri.islToGreg(y, m, d, 0);
    hmonth = hdate[1];
    hyear = hdate[2];
    hday = hdate[0];

    month.setCurrentItem(hmonth);
    day.setCurrentItem(hday);
    year.setCurrentItem(hyear);

}

public void setHijri(int y, int m, int d) {
    hdate = hijri.GregToIsl(y, m, d, 0);
    hmonth = hdate[1];
    hyear = hdate[2];
    hday = hdate[0];

    hijrimonth.setCurrentItem(hmonth);
    hijriday.setCurrentItem(hday);
    hijriyear.setCurrentItem(hyear);
}
</code></pre>
