I have not understood how to return values from the method below, I have tried to return int
but it shows me a weird error which is not possible to solve. This is the code:
private void showTheEnemy() {
ViewTreeObserver vto = radarImage.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
radarImage.getViewTreeObserver().removeOnPreDrawListener(this);
yradar_height = radarImage.getMeasuredHeight();
xradar_width = radarImage.getMeasuredWidth();
return true;
}
});
coordinateText.setText(yradar_height + " " + xradar_width);
}
I have understood that values are not being updated in the method because when I use setText()
method then int
values are 0.
You get zeros because the inner-method is not triggered before you set the text. The values are set at whatever they were when you last initialized them.
Set the text from the callback.
Or pass to another method.