Helpful Information
 
 
Category: BlackBerry Development
Navigation through menu

I have written the following code and having problem incrementing/decrementing the variable 'idx' so that the user can navigate to the other fact by means of a menu. But for some reason the value of 'idx' does not alter. Why is that happening?

class FactScreen extends MainScreen{
public int idx;
public FactScreen()
{
super();

HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.FIELD_HCENTER|Manager.NON_FOCUSABLE);
//LabelField lblFact = new LabelField("Sex Fact");
//add(lblFact);
String SexFacts[] = {"Light is a bad stimulus for sex", "It is always best to have sex after dinner", "Apart from humans dolphins do enjoy sex as well"};

int LeftEmptySpace = (Display.getWidth() - hfm.getPreferredWidth())/2;

int TopEmptySpace = Display.getHeight()/5; //- hfm.getPreferredHeight()*2);

hfm.setMargin(TopEmptySpace,0,0,LeftEmptySpace);

this.add(hfm);

RichTextField rtfFact = new RichTextField(SexFacts[idx]);
add(rtfFact);

// MenuItem MyMenuItem;

// MyMenuItem.toString("Next Fact");


addMenuItem(nextFact);
addMenuItem(MenuItem.separator(0));

addMenuItem(prevFact);
addMenuItem(MenuItem.separator(2));

}

private final MenuItem nextFact = new MenuItem("Next Fact",0,0)
{
public void run()
{
//Dialog.alert("Next Fact!");
idx = idx + 1; /*incrementing to go to the next fact*/
}


};

private final MenuItem prevFact = new MenuItem("Previous Fact",0,0)
{
public void run()
{
Dialog.alert("Previous Fact!");
idx = idx - 1;/*decrementing to go to the previous fact*/
}

};

}

Thanks,
Maxood










privacy (GDPR)