Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
dipanwita_dev
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer
Accepted Solution

issue regarding fieldchangeListener

hi,

i am using f fieldchange listener for four diiferent datefield.and i want when value of one datefield is changed and OK button is pressed.value according to my requirement should be set to 3 other datefield.and same case should be done for all other datefield.and one of those datefield changes its own valu first then others.for example if i select 2nd december it will set it to 2 days later value.and according to it other 3 datefields value should be changed.so i use field changelistener to each datefield.

 

But,problem is that it causes "Stack overflow exception".i have used flag value to each.but problem not resolved.

but if i use focus change listener its not arising problem.focus change not the correct one to use .i have to use fieldchange only.

 

wht to do?plz.....help me...

 

DateField gestagePicker = new DateField(" ", System.currentTimeMillis(),
            DateField.DATE) {
        protected void paint(Graphics graphics) {
            graphics.setColor(Color.BROWN);
            graphics.setBackgroundColor(Color.WHITE);
            super.paint(graphics);
        }

        protected void invalidate() {
            super.invalidate();
        }

    };

DateField mDatePicker = new DateField(" ", System.currentTimeMillis(),
            DateField.DATE) {

        protected void paint(Graphics graphics) {
            graphics.setColor(Color.BROWN);
            graphics.setBackgroundColor(Color.WHITE);
            if (isFocus()) {
                graphics.setBackgroundColor(Color.ROSYBROWN);
                // graphics.set(Color.PINK);
                // graphics.setGlobalAlpha(80);
            }
            super.paint(graphics);
        }

        public void invalidate() {
            super.invalidate();
        }
    };

FieldChangeListener listener = new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                // DateField mDatePicker = (DateField) field;
                /*
                 * DatepickerManager.cycleClick = false;
                 * DatepickerManager.lastPeriodflag = false;
                 * DatepickerManager.ultraFlag = false;
                 * DatepickerManager.estmateFlag = false;
                 * DatepickerManager.lutealClick = false;
                 */
                long periodDate = mDatePicker.getDate();
                if (DatepickerManager.lastPeriodflag) {
                    if (DatepickerManager.device) {
                        System.out.println("DeviceInfo.getDeviceId()"
                                + DeviceInfo.getDeviceName());
                        final long onePrior = (mDatePicker.getDate())
                                + (24 * 60 * 60 * 1000);
                        setConceptionDate(onePrior);
                        // checkValidity(periodDate,
                        // System.currentTimeMillis());
                        setgestation(periodDate, System.currentTimeMillis());

                    } else {
                        final long onePrior = (mDatePicker.getDate());

                        setConceptionDate(onePrior);

                    }// System.out.println("date in listener"
                    // + new

                }

            }

        };

        mDatePicker.setChangeListener(listener);

Please use plain text.
Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: issue regarding fieldchangeListener

You are getting stackOverflowException because you are changing date values on oither date fields on change of one field, and this process repeat recursively, and you get stackOverflow exception. You can use some flag to manage this, Just use following example as example, it is not implementation,

 

Like I have a flag that have value -1 initially,

 

chDate=-1;

 

in fieldchangeMethod

if(field==df1)

{

if(chDate==-1)

{

chDate=1;

df2.setDate();

df3.setDate();

chDate=-1;

}

}

Please use plain text.
Regular Contributor
dipanwita_dev
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer

Re: issue regarding fieldchangeListener

FieldChangeListener conListener = new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
// nDatePicker.getChangeListener().
if(field==nDatePicker){
if (DatepickerManager.conceptionFlag) {

long periodDate = mDatePicker.getDate()
- (24 * 60 * 60 * 1000);

// * checkValidity(nDatePicker.getDate(), System
// * .currentTimeMillis());

setLastPeriod(periodDate, nDatePicker.getDate(),
DatepickerManager.cycleNumber,
DatepickerManager.lutealNumber, dueDatePicker
.getDate());

setgestation(mDatePicker.getDate(), System
.currentTimeMillis());
DatepickerManager.conceptionFlag = false;
}
}
}
};
nDatePicker.setChangeListener(conListener);
used in this way...but still same exception
Please use plain text.
Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: issue regarding fieldchangeListener

Please confirm if issue you have been getting is solved or not.

Please use plain text.
Regular Contributor
dipanwita_dev
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer

Re: issue regarding fieldchangeListener

not yet resolved...i tried your suggestion,but no result..plz help

Please use plain text.
Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: issue regarding fieldchangeListener

FieldChangeListener conListener = new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
// nDatePicker.getChangeListener().
if(field==nDatePicker){
if (DatepickerManager.conceptionFlag) {
DatepickerManager.conceptionFlag = false;
long periodDate = mDatePicker.getDate()
- (24 * 60 * 60 * 1000);

// * checkValidity(nDatePicker.getDate(), System
// * .currentTimeMillis());

setLastPeriod(periodDate, nDatePicker.getDate(),
DatepickerManager.cycleNumber,
DatepickerManager.lutealNumber, dueDatePicker
.getDate());

setgestation(mDatePicker.getDate(), System
.currentTimeMillis());

}
}
}
};
nDatePicker.setChangeListener(conListener);

 

 

Do first think in body of if method to reset value of flag.

Please use plain text.
Regular Contributor
dipanwita_dev
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer

Re: issue regarding fieldchangeListener

thanks!
Please use plain text.
Regular Contributor
dipanwita_dev
Posts: 68
Registered: ‎08-16-2011
My Device: TMOBILE 8900
My Carrier: developer

Re: runtime alignment of text for various device

hi,

i have to download a file and set those texts of file in screen for various device.and i dont want to use setmargin feature for that beacause there are severel number of  device including touch and non touch.i want those lines to set in device screen according to resolution,height and widths.is it possible?please provide solution.....!

 

Please use plain text.