Spinner does not load data from string.xml

2

My spinner just shows the arrow. in 1 it has to show the states and so informed the 2 shows the cities of that state

Thisisthejavacode.

publicclassPropertyRegisterActivityextendsAppCompatActivityimplementsOnItemSelectedListener{privateSpinnerspProvincias;privateSpinnerspLocalidades;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_property_register);this.spProvincias=(Spinner)findViewById(R.id.sp_provincia);this.spLocalidades=(Spinner)findViewById(R.id.sp_localidad);loadSpinnerProvincias();}privatevoidloadSpinnerProvincias(){ArrayAdapter<CharSequence>adapter=ArrayAdapter.createFromResource(this,R.array.provincias,R.layout.spinner_item);adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);this.spProvincias.setAdapter(adapter);this.spProvincias.setOnItemSelectedListener(this);this.spLocalidades.setOnItemSelectedListener(this);}@OverridepublicvoidonItemSelected(AdapterView<?>parent,Viewview,intpos,longid){switch(parent.getId()){caseR.id.sp_provincia:TypedArrayarrayLocalidades=getResources().obtainTypedArray(R.array.array_provincia_a_localidades);CharSequence[]localidades=arrayLocalidades.getTextArray(pos);arrayLocalidades.recycle();ArrayAdapter<CharSequence>adapter=newArrayAdapter<CharSequence>(this,R.layout.spinner_item,android.R.id.text1,localidades);adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);this.spLocalidades.setAdapter(adapter);break;caseR.id.sp_localidad:break;}}@OverridepublicvoidonNothingSelected(AdapterView<?>parent){}}

Thisisxml.

<?xmlversion="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="view.PropertyRegisterActivity">

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="360dp"
        android:layout_height="82dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:contentDescription="TODO"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/ic_cadastrodepropiedade_logo"
        tools:ignore="VectorDrawableCompat" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="23dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/property_register_description"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.56"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView5"
        app:layout_constraintVertical_bias="0.096" />

    <EditText
        android:id="@+id/editYear"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="@string/hint_year"
        android:inputType="numberDecimal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView5"
        app:layout_constraintVertical_bias="0.309" />

    <EditText
        android:id="@+id/editProperty"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:ems="10"
        android:hint="@string/hint_property"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView5"
        tools:ignore="MissingConstraints,UnknownId" />

    <Button
        android:id="@+id/buttonSave"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/custom_button"
        android:text="@string/save"
        android:textColor="@color/text_color"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        tools:ignore="UnknownId" />


    <Spinner
        android:id="@+id/sp_provincia"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:spinnerMode="dropdown"
        android:prompt="@string/provincia_prompt"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView5"
        app:layout_constraintVertical_bias="0.648" />


    <Spinner
        android:id="@+id/sp_localidad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:spinnerMode="dropdown"
        android:prompt="@string/localidad_prompt"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imageView5"
        app:layout_constraintVertical_bias="0.805" />




</android.support.constraint.ConstraintLayout>

These are the layouts for the spinner.

spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:textColor="#ff0000" />

spinner_dropdown_item.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    android:textColor="#aa66cc"/>
    
asked by anonymous 27.12.2017 / 13:54

1 answer

0

Try switching from prompt to entries

android:entries="@array/tiposPessoa"

in strings.xml put the data

    <string-array name="tiposPessoa">
     <item>Selecione uma opção</item>
     <item>Usuário</item>
     <item>Gestor</item>
     <item>Usuário/Gestor</item>
    </string-array>
    
15.01.2018 / 14:48