本文介绍了getView()和getActivity()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

getView()getActivity()有什么区别?

我已经使用了这两种方法,但是即使使用方法在android中也是一样,我也不了解基本区别:

I have used both methods but don't understand the basic difference even methodology of usage are also same in android:

ListView deliverItemList = (ListView) getView().findViewById(R.id.load_item_list);
ListView deliverItemList = (ListView) getActivity().findViewById(R.id.load_item_list);

我假设getView()可能会产生NullPointerException,并与我分享您的知识,并且推荐哪种方法?

I have assumed that getView() may produce NullPointerException, share your knowledge with me and which method is recommended?

推荐答案

getActivity()返回托管FragmentActivity,而getView()返回您放大的视图并返回 onCreateView.后者仅在onCreateView返回

getActivity() returns the Activity hosting the Fragment, while getView() returns the view you inflated and returned by onCreateView. The latter returns a value != null only after onCreateView returns

这篇关于getView()和getActivity()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:18