Este es el codigo del main acticity de primer proyecto donde me funciona. package com.example.instalador.recufinal;
import android.content.res.TypedArray; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.Spinner;
public class MainActivity2 extends AppCompatActivity { private String[] caballosLetra; private TypedArray caballosFoto; private boolean cargar = false; private Spinner spinnerDam; private ImageView imagenCentral;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
caballosLetra = getResources().getStringArray(R.array.caballoLetra);
caballosFoto = getResources().obtainTypedArray(R.array.caballoFoto);
imagenCentral = (ImageView) findViewById(R.id.imagenCentral);
//Instanciamos el spinner
spinnerDam = (Spinner) findViewById(R.id.SpinnerDam2);
spinnerDam.setAdapter(new AdaptadorSpinner(this, R.layout.lineaadapter));
spinnerDam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(cargar == false){
cargar = true;
}else {
imagenCentral.setImageResource(caballosFoto.getResourceId(position, -1));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public String[] getCaballosLetra() {
return caballosLetra;
}
public TypedArray getCaballosFoto() {
return caballosFoto;
}
}
package com.example.instalador.recufinal;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Spinner;
public class MainActivity2 extends AppCompatActivity {
private String[] caballosLetra;
private TypedArray caballosFoto;
private boolean cargar = false;
private Spinner spinnerDam;
private ImageView imagenCentral;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
caballosLetra = getResources().getStringArray(R.array.caballoLetra);
caballosFoto = getResources().obtainTypedArray(R.array.caballoFoto);
imagenCentral = (ImageView) findViewById(R.id.imagenCentral);
//Instanciamos el spinner
spinnerDam = (Spinner) findViewById(R.id.SpinnerDam2);
spinnerDam.setAdapter(new AdaptadorSpinner(this, R.layout.lineaadapter));
spinnerDam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(cargar == false){
cargar = true;
}else {
imagenCentral.setImageResource(caballosFoto.getResourceId(position, -1));
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public String[] getCaballosLetra() {
return caballosLetra;
}
public TypedArray getCaballosFoto() {
return caballosFoto;
}
}