Refresh Image

Asked

Viewed 29 times

0

I have a question, because I’m setting the picture from Spinner’s position. Then, when you open Activity, the Oncreate method reads the position of the spinner and loads the image according to its type.

However, I would like to know how to set the position of Spinner whenever the user clicks on the spinner and change position.

teste = arrayLitros.get(spnProdutos.getSelectedItemPosition()).toString();
    teste2 = arrayUnidadeL.get(spnProdutos.getSelectedItemPosition()).toString();


    if(teste.equals("20") && teste2.equals("L")){
        imgProduto.setImageResource(R.drawable.img1);
    }
    else if(teste.equals("10") && teste2.equals("L")){
        imgProduto.setImageResource(R.drawable.img2);
    }
    else if(teste.equals("2") && teste2.equals("L")){
        imgProduto.setImageResource(R.drawable.img3);
    }
    else if(teste.equals("3") && teste2.equals("M")){
        imgProduto.setImageResource(R.drawable.img4);
    }
  • 2

    Use a OnItemSelectedListener. and attribute it to spinner with setOnItemSelectedListener()

  • Thanks for the light, I wasn’t paying attention to the existing methods.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.