Hi,
These are my first steps in Android, so my solution might not be
perfect, yet it works.
First of all, you should create a member in AlertDialogSamples class:
private int dialogSingleChoiceOption=0; //"0", because "Map" is
the default choice
Secondly, you have to act when somebody clicks on the dialog:
/* User clicked on a radio button do some stuff */
dialogSingleChoiceOption = whichButton;
Finally, to read the result when sb clicks "OK":
/* User clicked Yes so do some stuff */
String[] strArr = getResources().getStringArray
(R.array.select_dialog_items2);
String result = strArr[dialogSingleChoiceOption];
Log.d("!Result",result);
I recommend these two links:
http://developer.android.com/guide/topics/resources/resources-i18n.html
http://developer.android.com/guide/topics/resources/available-resources.html
Any questions?
On Jul 21, 7:16 am, "[email protected]" <[email protected]> wrote:
> Hello all,
>
> I'm playing with the AlertDialogSample.java program.
>
> I want to add lines in the code to get the value in the onClick
> methods.
>
> Please see the location marked as "==>" that I want to add lines.
>
> Could you please guide me what lines should be there?
>
> Thank you.
>
> case DIALOG_SINGLE_CHOICE:
> return new AlertDialog.Builder(AlertDialogSamples.this)
> .setIcon(R.drawable.alert_dialog_icon)
> .setTitle(R.string.alert_dialog_single_choice)
> .setSingleChoiceItems(R.array.select_dialog_items2, 0,
> new DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog, int
> whichButton) {
>
> /* User clicked on a radio button do some
> stuff */
> }
> })
> .setPositiveButton(R.string.alert_dialog_ok, new
> DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog, int
> whichButton) {
> /* User clicked Yes so do some stuff */
>
> =====>
> =====>
> }
> })
> .setNegativeButton(R.string.alert_dialog_cancel, new
> DialogInterface.OnClickListener() {
> public void onClick(DialogInterface dialog, int
> whichButton) {
>
> /* User clicked No so do some stuff */
> }
> })
> .create();
>
> case DIALOG_MULTIPLE_CHOICE:
> ................
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---