我正在创建自定义BaseAdapter
类
public class CustomAdapter extends BaseAdapter {
Context c;
ArrayList<String> items;
CustomAdapter(Context c,ArrayList<String> items)
{
this.c=c;
this.items=items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int i) {
return items.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
View v= view;
TextView tv;
LayoutInflater layoutInflater = (LayoutInflater)c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewHolder pattern;
if(view==null)
{
v = layoutInflater.inflate(R.layout.dummy,viewGroup,true);
tv = (TextView)v.findViewById(R.id.textView);
pattern = new ViewHolder(v);
v.setTag(pattern);
}
else{
pattern = (ViewHolder)v.getTag();
return v;
}
pattern.tv.setText(items.get(i));
return v;
}
}
我收到此错误,
addView(View, LayoutParams) is not supported in AdapterView
这是因为我在此代码中传递了true
v = layoutInflater.inflate(R.layout.dummy,viewGroup,true);
我的问题是为什么我们在这里传递时会出现错误? BaseAdapter
不接受吗?