Skip to main content

How to refresh BlackBerry ui page on button click?



I may seem ignorant but I have not found much information about how to go about my problem developing my BlackBerry application.





Basically I have constructed a UI that contains a few image buttons. What I want to do is when I click on one of the buttons, I want an image at the center of the screen to switch seemlessly to another image.





I am currently not using any threads though from what I've gathered I need to?





Or do I simply have to push a new screen in my button listener and recall the class's constructor and rebuild the page with different images?





Sorry if this is unclear, I would really appreciate some basic info on how to do this or a link that explains page refreshing in detail for blackberry!





Thanks alot





EDIT : Okay here is a very small part of my code :





This is basically the last thing I have tried in the listeners, I dont know how to change the image (flagField) when I press one of the two buttons! The only thing that worked for me was pushScreen(new Csps("americanflag")); every time I would press on a button, but the performance was bad and I was left with a stack of screens, not ideal.





I have been trying to do this all day long hehe... sigh , here goes:







public class CSP extends UiApplication

{

public static void main(String[] args)

{

CSP theApp = new CSP();

theApp.enterEventDispatcher();

}



public CSP()

{

CSPS csps = new CSPS();

pushScreen(csps);

}

}



class CSPS extends MainScreen implements FieldChangeListener

{



int width = Display.getWidth();

int height = Display.getHeight();



ButtonField backButton;



ImageButtonField canadianFlag;

ImageButtonField americanFlag;

Bitmap changeableFlag;

String currentFlag ="canada_flag.png";

BitmapField flagField;



canadianFlag = construct("canada_flag.png", 0.18);

americanFlag = construct("us.gif", 0.18);



canadianFlag.setChangeListener(this);

americanFlag.setChangeListener(this);



add(flagField);

add(canadianFlag);

add(americanFlag);

//LISTENERS

public void fieldChanged(Field field, int context){





if(field == canadianFlag){

setCurrentFlagResource("canada_flag.png");

BitmapField newFlagField = populateFlagField(currentFlag, 0.3);

replace(flagField, newFlagField);



this.invalidate();

this.doPaint();

this.updateDisplay();



}

else if(field == americanFlag){



setCurrentFlagResource("american-flag.gif");

BitmapField newFlagField = populateFlagField(currentFlag, 0.3);

replace(flagField, newFlagField);



this.invalidate();

this.doPaint();

this.updateDisplay();



}







the setCurrentFlagRessource method sets the flagField attribute to the appropriate BitmapField


Comments

  1. There is a method called setBitmap() in the BitmapField.

    In the listeners you should simply call flagField.setBitmap(newbitmap). You can also use the method setImage(). There is no need to call invalidate, updateUI etc.

    If you get any IllegalStateException while using this method, simply get a lock on the Applicaton Event lock object or invokeLater() this code.

    ReplyDelete
  2. You will only need to use threads if you are getting your images from some place that might block (like a web server). You should only need to update the images, though you may need to call invalidate() on your button or screen. What would really help is some information on what you are doing. You didn't even tell us what class you're using to display the image, if you've extended it or not, etc.

    ReplyDelete
  3. I don't know what you are doing in your code; But The way of refresh the screen is not like that;

    So, I change Your CSPS screen which you are trying to refresh the screen; See the below code...

    class CSPS extends MainScreen implements FieldChangeListener
    {

    int width = Display.getWidth();
    int height = Display.getHeight();

    ButtonField backButton;

    //ImageButtonField canadianFlag;
    //ImageButtonField americanFlag;
    Bitmap changeableFlag;
    String currentFlag ="canada_flag.png";
    BitmapField flagField;
    public CSPS()
    {
    createGUI();
    }

    public void createGUI()
    {
    canadianFlag = construct("canada_flag.png", 0.18);
    americanFlag = construct("us.gif", 0.18);

    canadianFlag.setChangeListener(this);
    americanFlag.setChangeListener(this);

    add(flagField);
    add(canadianFlag);
    add(americanFlag);
    //LISTENERS
    }

    public void fieldChanged(Field field, int context){


    if(field == canadianFlag)
    {
    setCurrentFlagResource("canada_flag.png");
    BitmapField newFlagField = populateFlagField(currentFlag, 0.3);
    replace(flagField, newFlagField);

    deleteAll();
    createGUI();
    invalidate();
    }
    else if(field == americanFlag)
    {
    setCurrentFlagResource("american-flag.gif");
    BitmapField newFlagField = populateFlagField(currentFlag, 0.3);
    replace(flagField, newFlagField);

    deleteAll();
    createGUI();
    invalidate();
    }
    }
    }




    Construct a createGUI() method, in that write the code that what you have to design for that screen. Not only this screen; What ever you are creating do like this;
    and



    deleteAll();
    createGUI();
    invalidate();




    For refresh the screen do the above three lines; delete all the fields and call again the createGUI() method; and at last invalidate();

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex