I want to execute some code immediately after the form is shown.
I want to check the size of a button on the form and use the same size to create a new button at runtime.
I tried onStart() and onResumed(), but they do not work.
Thanks, Ashok
I want to execute some code immediately after the form is shown.
I want to check the size of a button on the form and use the same size to create a new button at runtime.
I tried onStart() and onResumed(), but they do not work.
Thanks, Ashok
You can add a globallayout listener. Add the listener at onActivityCreated. Check this example:
button1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
button1.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
button1.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
//here the size is already available. create new button2 here with the size of button1
}
});
you are looking at the onCreate() method, that is the function that will run when your app is first loaded in to memory