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
Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified
Accepted Solution

problem with push and pop screen

hello ,

 

my problem is that when i click next button it will go from first page to second page,

then same again go from second page to third page.

now when i click back button,it will come on second page back and  again when i press it will come on page first.

 

but  problem is that,now if i click on next button it directly go to page fourth instead of page second.

please help me to solve it.

 

code:

 

class Main extends MainScreen

    ButtonField next1;
    ButtonField prev1;
    public int count;
 
    public Main(int con)
    {  
        count=con;
        setTitle("PAGE"+count);
     
        HorizontalFieldManager hfm1=new HorizontalFieldManager();
       
       
        next1=new ButtonField("Next",ButtonField.CONSUME_CLICK);
        next1.setChangeListener(new FieldChangeListener(){
        public void fieldChanged(Field field,int content){
        if(field==next1)
        {
              count=count+1;
              System.out.println("add"+count);
              UiApplication.getUiApplication().pushScreen(new Main(count));
        }
        }
        });          
        hfm1.add(next1);


             prev1=new ButtonField("Back",ButtonField.CONSUME_CLICK);
             prev1.setChangeListener(new FieldChangeListener(){
             public void fieldChanged(Field field,int content){
             if(field==prev1)
             {
                count=count-1;
                 UiApplication.getUiApplication().popScreen();
             }
             }
             });          
             hfm1.add(prev1);
        }   

}  

 

Highlighted
Developer
Posts: 53
Registered: ‎10-29-2010
My Device: Not Specified

Re: problem with push and pop screen

You don't have to change your variable count...

 

Replace

 

    if(field==next1) {
          count=count+1;
          System.out.println("add"+count);
          UiApplication.getUiApplication().pushScreen(new Main(count));
    }

 with

 

    if(field==next1) {
        UiApplication.getUiApplication().pushScreen(new Main(count + 1));
    }

 

And replace

 

    if(field==prev1) {
        count=count-1;
        UiApplication.getUiApplication().popScreen();
    }

with

 

    if(field==prev1) {
        UiApplication.getUiApplication().popScreen();
    }

 

 

 

 

 

 

Trusted Contributor
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: problem with push and pop screen

thanks for reply.

 

now it works properly.