我正在使用 baseadapter 创建自己的 listview 适配器,并且我想在运行时动态创建视图而不使用充气器。当我不使用 baseadapter 执行此操作时,它可以正常工作,但当我将代码放入 baseadapter 时却不行。
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
System.out.println("getView " + position + " " + convertView + " type = " + type);
if (convertView == null) {
switch (type) {
case TYPE_ITEM:
//convertView = mInflater.inflate(R.layout.item1, null);
LinearLayout ll = new LinearLayout(MainActivity.this);
TextView question = new TextView(MainActivity.this);
question.setTextSize(1,14);
question.setText("This is question");
ll = new LinearLayout(MainActivity.this);
ll.setOrientation(android.widget.LinearLayout.VERTICAL);
ll.addView(question);
convertView=ll;
break;
case TYPE_SEPARATOR:
convertView = mInflater.inflate(R.layout.item2, null);
break;
}
} else {
}
return convertView;
}