我想在不使用 xml 布局的情况下填充项目,而是想在运行时创建视图。这是我的getView()
方法。
public View getView(final int position, View convertView, ViewGroup parent) {
EditText v ;
if(convertView ==null)
{
v = new EditText(mContext);
convertView = v;
convertView.setTag(R.string.edittext_child, v);
}
else
{
v = (EditText)convertView.getTag(R.string.edittext_child);
}
v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 80));
v.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.custom_edit));
v.setEms(12);
v.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
v.setPadding(10, 0, 5, 0);
v.setHint(Ids[position]);
return convertView;
}
返回视图时出现此错误。
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams