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);
}
Use a
OnItemSelectedListener.
and attribute it to spinner withsetOnItemSelectedListener()
– ramaral
Thanks for the light, I wasn’t paying attention to the existing methods.
– Gabriel Henrique