I want to implement a selection menu that shows me a list in the following way:
I do not know with what kind of activity something like this can be implemented in Android Studio,
thank you very much
Something like what you want and simple would be this:
In the activity_mail.xml file
<?xml version="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=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.058" />
<Spinner
android:id="@+id/spinner"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
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/textView"
app:layout_constraintVertical_bias="0.042" />
</android.support.constraint.ConstraintLayout>
In the MainActivity.java file
//Implementas AdapterView.OnItemSelectedListener
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
//Array de strings con los nombres de lo que quieras.
private String[] miArray = {"Cuenca", "Quito", "Guayaquil", "Ibarra", "PortoViejo", "Loja", "Ambato", "Salinas", "Manta"};
//Objeto desplegable.
private Spinner miLista;
//Creas un adaptador.
ArrayAdapter<String> adaptador;
String nombreCiudad;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Casting del elemento spinner.
miLista = (Spinner) findViewById(R.id.spinner);
miLista.setOnItemSelectedListener(this);
//Instancia y paso de parametros para constructor.
adaptador = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, miArray);
//Cargo el adaptador al spinner.
miLista.setAdapter(adaptador);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.spinner:
//Creo una variable de tipo string para guardar el string y postion buscará la ciudad dentro
// del array que coincida para almacenarla.
nombreCiudad = miArray[position];
Toast toast = Toast.makeText(this, nombreCiudad, Toast.LENGTH_SHORT);
toast.show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
When you select it, you will be shown the selection with a Toast.