You can create a String
array with the options you want to show there and then pass the array to an AlertDialog.Builder
with the method setItems(CharSequence[], DialogInterface.OnClickListener)
.
An example:
String[] colors = {"red", "green", "blue", "black"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(colors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// the user clicked on colors[which]
}
});
builder.show();
The output (on Android 4.0.3):
(Background map not included. ;))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…