How to set the value of a spinner in an elegant way

1

Dear in an activity where we are making a change, I am setting the value of the spinner (rs)

     for(int i = 0; i < clienteAdapter.getCount(); i++) {

            Cliente elemento = (Cliente) clienteAdapter.getItem(i);

            if(elemento.getId() == pedido.getId_cliente()) {
                spCliente.setSelection(i);
                break;
            }
        }

I'm getting the data that populates SQLite's Spinner, would it have a more elegant way of doing this?

    
asked by anonymous 24.05.2017 / 02:39

1 answer

0

If you are using java8 to compile, you can use filter to search the list with predicates:

        Optional elemento = lista.stream().filter(c -> c.getId() == 1).findFirst();
        if (elemento.isPresent()){
            [...]
        }
    
24.05.2017 / 11:58