Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnPostCreate in Fragment

I am using a TextWatcher in my Activity at the onPostCreate but now I have turned it into a Fragment.

What's the equivalent of this in a Fragment?

  @Override
protected void onPostCreate(Bundle savedInstanceState) {
    mSearchView.addTextChangedListener(filterTextWatcher);
    super.onPostCreate(savedInstanceState);
}
like image 912
user3694470 Avatar asked Mar 27 '26 14:03

user3694470


1 Answers

Look at the Fragment Lifecycle. Wait until the Fragment is attached to the Activity

http://developer.android.com/guide/components/fragments.html

You can do your work in onActivityCreated.

To get Context use getActivity()

protected void onPostCreate (Bundle savedInstanceState)

Added in API level 1

Called when Activity start-up is complete (after onStart() and onRestoreInstanceState(Bundle) have been called). Applications will generally not implement this method; it is intended for system classes to do final initialization after application code has run.

Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

Parameters savedInstanceState If the Activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.

like image 199
Raghunandan Avatar answered Mar 29 '26 03:03

Raghunandan