AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose any item");
final List<String> lables = new ArrayList<>();
lables.add("List Item 1");
lables.add("List Item 2");
lables.add("List Item 3");
lables.add("List Item 4");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, lables);
builder.setAdapter(dataAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"You have selected " + lables.get(which),Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();We can always use ListView or RecyclerView for selection from list of items, but if we have small amount of choices and among those choices we want user to select one, we can use AlertDialog.Builder setAdapter
