How to fix the "array type expected to be found by java.util.arraylist"?

Given the function below, AndroidStudio produces an error in the marked line:

array type expected found java.util.arraylist

I also tried using getinstead of a direct link, but then Android Studio tells me something that setItemscannot 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();
}
+4
source share
1 answer

Edit

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:

Method setItems DialogBuilderexpects array, not arrayList.

+14
source

Source: https://habr.com/ru/post/1615462/


All Articles