gpt4 book ai didi

android - fragment 中的 OnPostCreate

转载 作者:太空狗 更新时间:2023-10-29 16:17:09 30 4
gpt4 key购买 nike

我在 onPostCreate 的 Activity 中使用了 TextWatcher,但现在我已经将它变成了 Fragment。

fragment 中的这个等价物是什么?

  @Override
protected void onPostCreate(Bundle savedInstanceState) {
mSearchView.addTextChangedListener(filterTextWatcher);
super.onPostCreate(savedInstanceState);
}

最佳答案

查看 fragment 生命周期。等到 Fragment 附加到 Activity

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

您可以在 onActivityCreated 中完成您的工作。

要获取 Context,请使用 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.

关于android - fragment 中的 OnPostCreate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221528/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com