Help with Spinner - Android Studio

Asked

Viewed 35 times

0

Hello,

I need to do a function that changes the image of an Imageview, according to what you have selected in a spinner and with input data "height" and "area". I’m doing it this way and it’s bugging when I click to run.

I appreciate the help!

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_procedimentos);

    final Spinner categorias = (Spinner)findViewById(R.id.spinner2);
     final ImageView tabela = (ImageView)findViewById(R.id.imageTabelas);
     final EditText editArea = (EditText)findViewById(R.id.editArea2);
     final  EditText editAltura = (EditText)findViewById(R.id.editAltura);
    Button btExecutar = (Button) findViewById(R.id.buttonExecutar);
    Button btVoltarInicio2 = (Button) findViewById(R.id.buttonVoltarInicio2);



    btExecutar.setOnClickListener(new View.OnClickListener() {
        private int contentView;

        public void onClick(View view) {

            Double area;
            Double altura;

            final Spinner categorias = null;

            if (editArea.getText().toString().isEmpty()){
                area = 1.00;
            }
            else{
                area = Double.parseDouble(editArea.getText().toString().trim());
            }

            if (editAltura.getText().toString().isEmpty()){
                altura = 1.00;
            }
            else{
                altura = Double.parseDouble(editAltura.getText().toString().trim());
            }


            categorias.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView <?> parent, View view, int position, long id) {
                    ImageView tabela = null;



                    if(categorias.getSelectedItem().equals("Grupo A") && altura<750 && area<500{
                        tabela.setImageResource(R.drawable.teste);
                    }
                }
            });

        }});
  • Which bug comes?

  • vc is creating the spinner and imageview again inside the onclick button. using them to effect onclick and setImage and they are null.

No answers

Browser other questions tagged

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