【发布时间】:2011-06-27 14:34:42
【问题描述】:
public class BottomToolbar extends RelativeLayout {
private Spinner circleSpinner;
private ImageButton operatorImageButton;
private ToggleButton conntypeToggleButton;
private Context context;
public BottomToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.toolbar, this);
this.context = context;
circleSpinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.circlesarray,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
circleSpinner.setAdapter(adapter);
}}
上面的代码创建了一个工具栏,其布局在 XML 中定义。但在 XML 视图中显示以下错误:
无法实例化以下类: - com.example.BottomToolbar
如果我评论这些行,则会出现错误:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.circlesarray,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
circleSpinner.setAdapter(adapter);
请帮忙,我怀疑数组适配器声明中的“上下文”有问题。
--提前致谢
【问题讨论】: