问题描述
谁能告诉我是什么 convertView
参数在 getView()
的方法<$用于C $ C>适配器类?
下面是一个简单的code执行从here:
@覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){
视图V = convertView;
如果(V == NULL){
LayoutInflater VI =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
V = vi.inflate(R.layout.row,NULL);
}
订购O = items.get(位置);
如果(O!= NULL){
TextView的TT =(TextView中)v.findViewById(R.id.toptext);
TextView的BT =(TextView中)v.findViewById(R.id.bottomtext);
如果(TT!= NULL){
tt.setText(姓名:+ o.getOrderName()); }
如果(BT!= NULL){
bt.setText(状态:+ o.getOrderStatus());
}
}
返回伏;
}
我应该通过 convertView
我们传递?
我发现什么,采取从这里:
您不应该由自己来调用该方法。
Android的的ListView
使用了适配器
来填补自己与浏览
。当的ListView
显示,它开始调用 getView()
来填充自己。当一个新的观点应该创建用户滚动,所以对于性能的的ListView
发送适配器
的旧观点,这是不再使用的 convertView
参数。
Can someone tell me what the convertView
parameter is used for in the getView()
method of the Adapter
class?
Here is a sample code take from here:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Order o = items.get(position);
if (o != null) {
TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
if (tt != null) {
tt.setText("Name: "+o.getOrderName()); }
if(bt != null){
bt.setText("Status: "+ o.getOrderStatus());
}
}
return v;
}
What should we pass via convertView
?
What I've found, take from here:
You shouldn't be calling that method by yourself.
Android's ListView
uses an Adapter
to fill itself with Views
. When the ListView
is shown, it starts calling getView()
to populate itself. When the user scrolls a new view should be created, so for performance the ListView
sends the Adapter
an old view that it's not used any more in the convertView
param.
这篇关于什么是&QUOT; convertView&QUOT;在ArrayAdapter getView参数()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!