我正在向用户展示一个包含 2 个项目的警报对话框,我想为这两个项目实现一个 OnClickListener。我可以设置 1 项,但是当我尝试使用 switch 语句时,我收到此错误:
无法打开 CharSequence[] 类型的值。只允许可转换的 int 值或枚举常量
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
final CharSequence[] items = {"Reviews", "More Info"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Please Select an Option");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch (items){
case 1 :
//do something
case 2:
Intent intent = new Intent (MyActivity.this, WebViewActivity.class);
MyActivity.this.startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();