为什么 base 参数在布局充气器中给出错误?
Why does the base parameter give an error in the layout inflator?
我正在创建自定义 BaseAdapter
class,
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);
我的问题是为什么我们在这里传递true时会出现错误? BaseAdapter
不接受吗?
我正在创建自定义 BaseAdapter
class,
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);
我的问题是为什么我们在这里传递true时会出现错误? BaseAdapter
不接受吗?