03-08-2011 10:07 AM
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);
}
}
Solved! Go to Solution.
03-08-2011 11:13 AM
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();
}
03-09-2011 12:03 AM
thanks for reply.
now it works properly.