#1
  1. Editor-in-Beef
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2008
    Location
    South Florida
    Posts
    466
    Rep Power
    10

    Post Advanced Java Programming for BlackBerry Smartphones


    BlackBerry and Java have a long and storied history together. Since the launch of the BlackBerry 5810 in 2002, all BlackBerry smartphones have been Java-based. All core BlackBerry applications have been written in Java. As you can see, there are many benefits to being familiar with Java, especially as it pertains to being a BlackBerry developer. Read More...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0

    Navigating through menu to other facts


    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

IMN logo majestic logo threadwatch logo seochat tools logo