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);
}
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()andonRestoreInstanceState(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
savedInstanceStateIf the Activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied inonSaveInstanceState(Bundle). Note: Otherwise it is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With