Does not change the image when making a set in android studio [closed]

0

What I try to do is that when any condition is met, a change of image is made to another. But it does not make any change, and I do not know why, if someone could indicate where I'm wrong or if the type of set is not compatible and such would be very grateful, I leave you attached the code:

languages=(Spinner)findViewById(R.id.spLanguage);
        items= getResources().getStringArray(R.array.language);
        tv=(TextView)findViewById(R.id.tvIdioma);
        image=(ImageView)findViewById(R.id.bandera);
        ArrayAdapter<String>adapter = new ArrayAdapter<String>(getBaseContext(),
                android.R.layout.simple_spinner_item,items);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        languages.setAdapter(adapter);
        languages.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
            @Override
            public void onItemSelected(Spinner parent, View view, int position, long id) {
                String text;
                text= (String) parent.getSelectedItem();
                if(text.equals("Spanish")){
                    image.setBackground(getResources().getDrawable(R.drawable));
                }else{
                    if(text.equals("English")){
                        image.setImageResource(R.drawable.gb);
                    }
                }
                tv.setText(text);
            }
        });

Look at the Spinner method:

languages.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
            @Override
            public void onItemSelected(Spinner parent, View view, int position, long id) {
                String text;
                text= (String) parent.getSelectedItem();
                if(text.equals("Spanish")){
                    image.setBackground(getResources().getDrawable(R.drawable));
                }else{
                    if(text.equals("English")){
                        image.setImageResource(R.drawable.gb);
                    }
                }
                tv.setText(text);
            }
    })
    
asked by Geany 26.12.2016 в 17:10
source

1 answer

1

In both cases try with:

image.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.gb));

or

image.setBackgroundResource(R.drawable.gb);

If necessary you have a trim to text to eliminate spaces

text = text.trim();
    
answered by 26.12.2016 в 17:26