0

It may seem a silly question but I've tried a variety of ways and have no idea how to solve. I am new to android programming and am completing a spinner with a list of objects. When you select the object in need spinner pick up the object ID and the number of animals of the same. My last attempt was is, but I know he does not enter the IF because the equals can not compare the list with a string, but do not know how to make this comparison.

   String posicaoSpinner = String.valueOf(sLote.getSelectedItemPosition());

    int idLote =0;
    int qtdAnimais;
    for (int i = 0; i < loteList.size(); i++) {
        for (Lote lotes : loteList) {
            if (posicaoSpinner.equals(loteList.get(i))) {
                idLote = Integer.valueOf(String.valueOf(lotes.get_id()));

                qtdAnimais = lotes.getQtd_animais() - itemPovoamento.getAnimais();
                lotes.setQtd_animais(qtdAnimais);
            }
        }
    }

Any help is welcome. Thank you so much

Raphael MM
  • 103
  • 8
  • Your question is not clear. so make it clear first. – M D Dec 08 '15 at 12:33
  • Well, I have a spinner that is filled with a list of objects. When I select an item from the spinner must pick up the object ID and quantity. But how can I compare the position of the spinner to the list of position? – Raphael MM Dec 08 '15 at 13:04

1 Answers1

1

If you need the value of the selected item you can simply use .getSelectedItem() of the spinner. So:

String posicaoSpinner = posicaoSpinner.getSelectedItem().toString();

should do the trick?

spcial
  • 1,529
  • 18
  • 40
  • This would not work because my spinner has 3 fields of an object: ID - number - name, and is something like this: 1-1000 - fish, if I get the selected item will take the entire string, and I need to get only the ID and the amount to subtract it. – Raphael MM Dec 08 '15 at 13:08
  • So I'm trying to work with the position of the spinner and the object's position in the list que will be the same in his position spinner. I do not know if this is the best logic to it = / – Raphael MM Dec 08 '15 at 13:12
  • Actually I don't clearly understand what you mean. You could provide your question with more code-details. If you want to use custom objects in a spinner (where you can store and handle several attributes) you could create a custom adapter. Here is a good example: http://stackoverflow.com/a/8116756/2492068 – spcial Dec 08 '15 at 13:51
  • Hey man this is exactly what I need, sorry for not able to be clearer, in fact I myself was a bit confusing. Very very thank you! =D – Raphael MM Dec 08 '15 at 14:09