alishaik786
alishaik786

Reputation: 3726

Change the Screen Orientation in Blackberry?

In my Application, I want to show the screens according to the Orientation. I knew, Whenever the device is Oriented then sublayout() method of current screen is called. According that point of view I write like this:

Here StartUp is another className;

This is my LoadingScreen.java Class;

public class LoadingScreen extends MainScreen
{
public LoadingScreen()
{       
    createGUI();
}

protected void sublayout(int width, int height) 
{
    StartUp.screenOrientation();        
    if(StartUp.isLandscape)
    {
        deleteAll();
        createGUI();            
        invalidate();           
    }
    else
    {   
        deleteAll();
        orientGUI();            
        invalidate();
    }
    super.sublayout(width,height);  
}

public void createGUI()
{
    //For LANDSCAPE Display;
}

public void orientGUI()
{
    //For PORTRAIT Display;
}   
}

The screenOrientation() method is this:

public static void screenOrientation()
{
    if(Display.getOrientation()==Display.ORIENTATION_LANDSCAPE)     
    {
        isLandscape=true;
        width=480;
        height=360;
    }
    else
    {
        isLandscape=false;
        width=360;
        height=480;
    }
}

I am getting the Screen in both Orientation Modes. My problem is, if I take one textboxField and enter something in LANDSCAPE Mode and Oriented to PORTRAIT Mode then the data is gone. Because I am calling createGUI(); or orientGUI(); methods in sublayout().

One more problem that I am getting in Touch screen is:

If I want to enter text in any textboxField It opens the "keypad". Its Not a problem. The main thing is whenever the keypad open/hide both times again calling the sublayout() of that class. So I am getting the refreshed screen.

So, is there any other method to get Orientation? If it is then help me.

Upvotes: 1

Views: 829

Answers (1)

rfsk2010
rfsk2010

Reputation: 8611

To solve the first issue, you have two options.

  • Dont delete the fields, just redraw the screen for the different orientation.

or

  • Save the value of textboxfield before you delete the field and after orientation change, set the value of textboxfield with the saved value. You will need to even get the cursor position and set that as well.

To solve the second issue

After orientation change, set a new variable "currentWidth" as Display.getWidth() . Then when you get a call to sublayout() check the Display.getWidth() and see if its equal to currentWidth. If its equal that means the orientation hasn't changed. If not then the orientation has changed.

hope this helps

Upvotes: 2

Related Questions