Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

AlertDialog - How do I get the message to show?

I have a Alert dialog that I wish to show at a particular point during my app's process (currently on selecting a listview item).
I have tried many varieties of the AlertDialog and can show the Alert but no matter what, the message will never show.

Here are two examples that I have seen working for others perfectly fine but still do not show the message for myself:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alertDialog = builder.Create();
alertDialog.SetTitle("Alert");
alertDialog.SetMessage("downloadingfile");
alertDialog.Show();

new AlertDialog.Builder(this)
    .SetPositiveButton("Yes", (sent, args) =>
    {
                    // User pressed yes
                })
    .SetNegativeButton("No", (sent, args) =>
    {
                    // User pressed no 
                })
    .SetMessage("downloadingfile")
    .SetTitle("Alert")
    .SetCancelable(false)
    .Show();

They are both located in a separate function that is called when a listview item is pressed.
Am I missing some sort of referencing or doing something wrong?
Or is perhaps one of my "using" overwriting the correct reference for AlertDialog?
(Usings in question)

using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using Java.IO;
using Java.Lang;
using Java.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.Json;
using System.Collections.Generic;

Any ideas would be greatly appreciated.

Thank you in advance.

Answers

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭

    Hello @MathewPotrykus

    i'm not an expert but try to use this

    `
    RunOnUiThread(() =>
    {
    //
    builder .Show();
    });

    `

    hope this help

  • MathewPotrykusMathewPotrykus USMember ✭✭

    Hi @ChristopheBERNARD ,

    Thank you for the reply, but all that seemed to do was bring up a UI layer and show nothing
    (dimmed entire screen like a black piece of film had been layered onto)

    Even if I place a AlertDialog into the Thread it just appears underneath the layer and still shows no Message :(

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    place return builder.Create(); instead of .Show

  • Michael_ShapiroMichael_Shapiro USMember ✭✭✭

    well.. I think your code is not really correct. Here is the working example:

    public class InfoBoxFragment :  DialogFragment
    {
        .....
        .....
        public override Dialog OnCreateDialog(Bundle savedInstanceState)
        {
            AlertDialog.Builder builder = new AlertDialog.Builder(Activity);
            builder.SetNeutralButton("OK", aButton);
    
            builder.SetTitle(Title);
            builder.SetMessage(Msg);
    
            return builder.Create();
        }
    }
    
Sign In or Register to comment.