I have a normal spinner working perfect and I have the following code:
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener {
private ArrayAdapter<String> adapter;
public ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
adapter.add("A");
adapter.add("B");
spinner.setAdapter(adapter);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setOnItemSelectedListener(this);
img = (ImageView) findViewById(R.id.imgView);
img.setImageResource(R.drawable.imgFundo);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String escolhido = adapter.getItem(position);
if(escolhido == "A") {
img.setImageResource(R.drawable.imga);
Toast.makeText(this, "entrou no if ", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
Note: Images are in png
But this code is not working ...
LOGCAT: 15: 02: 00.790 22578-22578 / A / libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code = 1), thread 22578
11-05 10: 07: 44,042 17694-17694 / E / dalvikvm-heap: Out of memory on a 9288016-byte allocation.
It does not change as required. How can I fix it?