I've been searching around trying to figure out how to create a popup or a dialog that has 4 options to choose from.
I see this picture on the Android developer site:
Does anyone know how to code up something like the one on the right? I don't need any icons next to my text, I just need to be able to select from 4 options.
The pop ups are nothing but
AlertDialog
.So you just need to createAlertDialog
, then inflate your desired view usingLayoutInflater
and set the inflated view usingsetView()
method ofAlertDialog
You can create a
CharSequence
array with the options you want to show there and then pass the array to anAlertDialog.Builder
with the methodsetItems(CharSequence[], DialogInterface.OnClickListener)
.An example:
The output (on Android 4.0.3):
(Background map not included. ;))
Try this :
public void onClick(View v) {
}