caipivara
8/24/2016 - 9:02 PM

Android - Dialog with custom view

Android - Dialog with custom view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:padding="@dimen/spacing_large">

  <Spinner
    android:id="@+id/date_spinner_date"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

View dialogView = getLayoutInflater().inflate(R.layout.date_picker_dialog, null);

String[] dates = //...
ArrayAdapter dateAdapter =
    new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, dates);
((Spinner) dialogView.findViewById(R.id.date_spinner_date)).setAdapter(dateAdapter);

new AlertDialog.Builder(this)
    .setTitle("Demo Date Picker")
    .setView(dialogView)
    .setCancelable(true)
    .setPositiveButton("OK", (dialog, which) -> {

    })
    .setNegativeButton("Cancel", (dialog, which) -> dialog.cancel())
    .show();