1
I would like to know how to put the values that will appear in Spinner
.
I already have the values, they will always be the same, without the need to come from a database. The problem (or not) is that this Spinner
is inside a Dialog
that I created to perform the filter action of a particular list.
Below is the predefined Spinner values:
<string-array name="spinner">
<item>título</item>
<item>descrição</item>
</string-array>
Below the Spinner XML:
<Spinner
android:id="@+id/dlg_filtro_spn_filtro"
style="@style/spinner_style"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dlg_filtro_lb_filtro" />
And below the Dialog class where I use to make the filter (where is located the due Spinner):
package br.com.alura.blocodenotas.dialog;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import br.com.alura.blocodenotas.R;
public class DialogFiltro extends AlertDialog.Builder {
private String cancelar;
private String filtrar;
@SuppressLint("NewApi")
public DialogFiltro(Context context) {
super(context);
this.setView(R.layout.dialog_filtro);
this.setCancelable(true);
this.setCancelar("CANCELAR");
this.setFiltrar("FILTRAR");
}
public DialogFiltro setCancelar(String cancelar) {
this.cancelar = cancelar;
return this;
}
public DialogFiltro setFiltrar(String filtrar) {
this.filtrar = filtrar;
return this;
}
public DialogFiltro setOnCancelarListener(DialogInterface.OnClickListener onClickListener) {
this.setNegativeButton(this.cancelar, onClickListener);
return this;
}
public DialogFiltro setOnFiltrarListener(DialogInterface.OnClickListener onFiltrarListener) {
this.setPositiveButton(this.filtrar, onFiltrarListener);
return this;
}
public Dialog build(){
return this.create();
}
}
What is your specific difficulty? The mode(s) (s) of filling a Spinner are the same regardless of where it is done(Activity, Fragment or other).
– ramaral
@ramaral, I call the Dialog class (where it contains the spinner) in my main class, but if I try to make a findViewById within the class that extends the Dialog, I can’t. And if I do findViewById in the main Activity, the object is null. My question was how to use it in the right way.
– GUSTAVO HENRIQUE LOPES SPACHUK