问题描述
片段
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//inflater provided
View view;
...
return view;
}
BaseAdapter:
BaseAdapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//have to make a constructor to get an inflater
....
return view;
}
为什么 BaseAdapter
的 getView()
做方法参数犯规提供了一个 LayoutInflater
与片段的
onCreateView()
?其中,在这种方法,我们预计将膨胀的意见?
Why does BaseAdapter
's getView()
method parameters doesnt provide an LayoutInflater
unlike Fragment
's onCreateView()
? Wherein in this method we are expected to inflate views?
充气观点要求我们有一个参考的 LayoutInflater
。
Inflating views requires that we have a reference to an LayoutInflater
.
推荐答案
其中的一个原因可能是,大部分的时间观将被重用。当视图被重用,即第二个参数视图不为空,你将不会被使用充气。因此这可能是为什么该API被设计以这种方式的原因。
One of the reason could be, most of the times Views will be reused. When the view is reused i.e. the second parameter View is not null, you will not be using the Inflater. Hence that could be the reason why the API has been designed in that way.
在片段的情况下,你将不得不使用API或膨胀的资源可以创建一个布局。由于最佳实践是分离出来的活动行为的UI设计,大部分时间充气器被使用。这些都是在href=\"http://developer.android.com/guide/components/fragments.html\" rel=\"nofollow\">官方文档的
In case of Fragments, you will have to create a layout either by using APIs or inflating a resource. Since the best practice is to separate out the UI design from Activity's behavior, most of the time Inflater is used. These are the statements provided in the official documentation.
要从onCreateView()返回一个布局,可以从它充气
在XML中定义的布局资源。为了帮助你这样做,onCreateView()
提供了LayoutInflater对象。
这篇关于Android的BaseAdapter上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!