Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Activity method is called after all the layout methods?

I need to do something in an Activity after all the layout methods have been called, all the Views are in place and the Activity is ready to be displayed.

Which method can do that?

like image 600
Marcos Vasconcelos Avatar asked Sep 19 '11 17:09

Marcos Vasconcelos


People also ask

Why do we need to call setContentView () in onCreate () of activity class?

As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.

How can we call method in activity from non activity class?

onCreate(savedInstanceState); setContentView(R. layout. main2); DataClass dc = new DataClass(); dc. show(); } public void call(ArrayList<String> arr) { // Some code... } }

What is setContentView?

SetContentView is used to fill the window with the UI provided from layout file incase of setContentView(R. layout. somae_file). Here layoutfile is inflated to view and added to the Activity context(Window).

How do you get a response from an activity in Android?

You must call the second activity using the startActivityForResult method. In your second activity, when it is finished, you can execute the setResult method where basically you put the result information. Then, on your first activity, you override the onActivityResult method.


1 Answers

If you are trying to get a width of a view or something. This should work

Add this to your activity's onCreate

ViewTreeObserver vto = layout.getViewTreeObserver(); 
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
    @Override 
    public void onGlobalLayout() { 
        // Put your code here. 

        layout.getViewTreeObserver().removeOnGlobalLayoutListener(this); 
    } 
}); 
like image 155
blessanm86 Avatar answered Oct 06 '22 01:10

blessanm86