0

I use this methods when I rotate the screen to load the state before:

public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    view1 = new DrawView(this);
    setContentView(view1);
    Bundle bundle = this.getIntent().getExtras();
    onRestoreInstanceState(bundle);
    getCoordinates();//NO WORKS WELL
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
    //Here I set the values ​​to images: colors, borders, etc ...
}

And I have in the AndroidManifest the next line:

android:configChanges="orientation|screenSize"

In the getCoordinates() method I have the next code:

public void getCoordinates(){
    final int[] values = new int[2];
    image.getLocationInWindow(values);
    x = values[0];
    y = values[1];
    width = image.getWidth();
    height = image.getHeight();
}

The previous code is not exactly what I have but it serves as an example. My real code not change much. But I have a problem, I have to know the coordinates of a image to draw lines between images. But if I launch the method by example (onConfigurationChanged(Configuration newConfig) ), as the method hasn't executed all lines yet and the method is not over, then the UI isn't load completely. Therefore get nulls in the coordinates. I don't know how to launch the method getCoordinates() automatically once it's fully charged the user interface to obtain the coordinates. Anybody can help me?

THANKS!!!!

Adrian
  • 336
  • 6
  • 22

1 Answers1

0

Add a layout listener.

See: How can you tell when a layout has been drawn?

Community
  • 1
  • 1
HeavyE
  • 2,132
  • 1
  • 23
  • 31