鉴于以下功能,AndroidStudio在标记行中给出错误:
array type expected found java.util.arraylist
我还尝试使用get
而不是直接引用,但Android Studio告诉我setItems
无法解决的问题。代码在这里:
protected void multiSelect(final ArrayList items) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Selection")
.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Log.i("Select", "Selected entry: " + items[item]); // error here
}
});
builder.create();
}
答案 0 :(得分:21)
更改
Log.i("Select", "Selected entry: " + items[item]);
到:
Log.i("Select", "Selected entry: " + items.get(item));
并更改
protected void multiSelect(final ArrayList items)
到
protected void multiSelect(final ArrayList<String> items)
<强>更新强>
setItems
的{{1}}方法需要DialogBuilder
,而不是array
。