Load spinner in a specific layout

0

I had managed to deploy a spinner in a project but now I'm doing it loading it from different layouts and I can not show it, any idea of where to put the code I had before in the new project? ! [This is the interface, the two buttons above are in one layout, the three remain in another and the blank space is other ] 1

This is the code of the main acticity of the first project where it works for me.

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;
    }


}
    
asked by Xabier 14.03.2017 в 09:48
source

1 answer

0

You should create the Spinner values in the XML which is called strings.xml and then quote them.

I leave you the page that explains how to use it.

link

    
answered by 15.03.2017 в 11:49