Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51707a97 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Checks if an adapter item is null before addint it to options."

parents 36a44f07 11920562
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -498,18 +498,30 @@ public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
    public void onProvideAutofillStructure(ViewStructure structure, int flags) {
        super.onProvideAutofillStructure(structure, flags);

        if (getAdapter() == null) return;
        final SpinnerAdapter adapter = getAdapter();

        if (adapter == null) return;

        // TODO(b/33197203): implement sanitization so initial value is only sanitized when coming
        // from resources.

        final int count = getAdapter().getCount();
        final int count = adapter.getCount();
        int size = 0;
        if (count > 0) {
            final String[] options = new String[count];
            for (int i = 0; i < count; i++) {
                options[i] = getAdapter().getItem(i).toString();
                final Object item = adapter.getItem(i);
                if (item != null) {
                    options[size++] = item.toString();
                }
            }
            if (size == count) {
                structure.setAutofillOptions(options);
            } else {
                final String[] validOptions = new String[size];
                System.arraycopy(options, 0, validOptions, 0, size);
                structure.setAutofillOptions(validOptions);
            }
        }
    }