3
I’m in doubt how to put a spinner in a Alertdialog, I already have the codes ready, just need to insert the spinner.
Array:
<string-array name="categoria_array">
<item>Aeroporto</item>
<item>Bar</item>
<item>Casa Noturna</item>
<item>Cinema</item>
<item>Colégio</item>
<item>Loja</item>
<item>Museu</item>
<item>Parque</item>
<item>Restaurante</item>
<item>Rodoviárias</item>
<item>Shoppings</item>
<item>Supermercado</item>
<item>Teatro</item>
<item>Universidade</item>
<item>Outro</item>
</string-array>
Layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/titulo"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="NOVA LOCALIZAÇÃO"
android:textColor="@color/colorWhite"
android:textSize="20sp"
android:textStyle="bold"
/>
<EditText
android:id="@+id/edt_nome"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/titulo"
android:layout_margin="15dp"
android:background="@drawable/border_transp_black_redond"
android:hint=" Nome do Local"
android:padding="5dp"
android:textColorHint="@color/colorPrimaryText"
android:textSize="20sp"
android:textStyle="italic" />
<EditText
android:id="@+id/edt_endereco"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/edt_nome"
android:layout_margin="15dp"
android:background="@drawable/border_transp_black_redond"
android:hint=" Endereço"
android:padding="5dp"
android:textColorHint="@color/colorPrimaryText"
android:textSize="20sp"
android:textStyle="italic" />
<EditText
android:id="@+id/edt_website"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/edt_endereco"
android:layout_margin="15dp"
android:hint=" WebSite"
android:padding="5dp"
android:inputType="textWebEditText"
android:textStyle="italic"
android:textColorHint="@color/colorPrimaryText"
android:textSize="20sp"
android:background="@drawable/border_transp_black_redond"/>
<EditText
android:id="@+id/edt_telefone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@id/edt_website"
android:layout_margin="15dp"
android:hint=" Telefone"
android:padding="5dp"
android:inputType="number"
android:textStyle="italic"
android:textColorHint="@color/colorPrimaryText"
android:textSize="20sp"
android:background="@drawable/border_transp_black_redond"/>
<Spinner
android:id="@+id/spinner_catogorias"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edt_telefone"/>
</RelativeLayout>
Metodo Alertdialog:
private void chamarDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
builder.setView(inflater.inflate(R.layout.layout_newcheckin, null));
//Dialog dialog = builder.show();
//dialog.dismiss(); fecha o dialog
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(), "Cliked OK!", Toast.LENGTH_SHORT);
return;
}
});
builder.show();
}
What exactly is your doubt?
– ramaral
If I need to create a class for the spinner or if I have to call it in Dialog, how would I do it. I don’t have much experience in android, to start now
– Lari Souza
That’s correct. You’re wondering how to get the spinner value is this?
– Caique Oliveira
Like I did the array with the values, but as I will make this values appear in the spinner, in case my doubt is how to load the spinner with the array values.
– Lari Souza