Given the function as below, AndroidStudio gives an error in the labeled line:
array type expected found java.util.arraylist
I also tried to use get
instead of a direct referencing, but then Android Studio is telling me something that setItems
cannot be resolved. The code is here:
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();
}
Change
Log.i("Select", "Selected entry: " + items[item]);
to :
Log.i("Select", "Selected entry: " + items.get(item));
and change
protected void multiSelect(final ArrayList items)
to
protected void multiSelect(final ArrayList<String> items)
UPDATE:
the setItems
method of the DialogBuilder
expects an array
, not an arrayList
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With