2

My application consists of a MapActivity, which loads an XML view (map_layout), containing a MapView and a CustomView which extends ImageView.

I use the following code to setup my MapActivity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_layout);
    initialise();
}

Then in initialise, I retrieve the MapView and CustomView from the XML file using findViewById(...) as usual.

Within the onMeasure(...) function of my CustomView I use this.getWidth() and this.getHeight() to get its dimensions, which returns the correct results.

Then within my initialise() code I decided to check if GPS is enabled (using code similar to the first answer here: How do I find out if the GPS of an Android device is enabled), showing an AlertDialog if GPS is disabled.

The problem is now that the onMeasure(...) function of my CustomView no longer works correctly, and this.getWidth() and this.getHeight() both return 0 if the AlertDialog gets displayed.

Why is this the case?

Thanks for your help in advance, if my question is unclear I'll edit it to add the full code when I have chance.

Community
  • 1
  • 1
woodstock365
  • 1,680
  • 4
  • 19
  • 34

1 Answers1

2

Okay, I needed to get the height and width within onLayout() instead of onMeasure() for some reason.

woodstock365
  • 1,680
  • 4
  • 19
  • 34