1
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) {
}
}
Obs : Images are in png
But that code isn’t 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 arrange?
Good evening Augusto, where is the Logcat? It can be dump of memory.
– Guilherme Nascimento
Guilhermenascimento previously believed that the problem was an error because the img was large, but when analyzing the logcat I saw that it was a memory error 11-05 10:07:44.042 17694-17694/ E/dalvikvm-heap: Out of memory on a 9288016-byte allocation. How can I fix ?
– Augusto Furlan
As suspected dump of memory, I will formulate an answer, I think I saw the same problem somewhere, already return.
– Guilherme Nascimento
OK obg I’m on hold
– Augusto Furlan