10

Xamarin.Android でメッセージ ボックスを表示するにはどうすればよいですか? メッセージ ボックスから yes または no の応答を得るにはどうすればよいですか?

- - 更新しました :

myBtn.Click += (sender, e) => 
{
   new AlertDialog.Builder(this)
   .SetMessage("hi")
   .Show();
};
4

2 に答える 2

20

AlertDialog.Buider内からクラスを使用できますActivity

new AlertDialog.Builder(this)
    .SetPositiveButton("Yes", (sender, args) =>
    {
        // User pressed yes
    })
    .SetNegativeButton("No", (sender, args) =>
    {
        // User pressed no 
    })
    .SetMessage("An error happened!")
    .SetTitle("Error")
    .Show();
于 2013-05-21T01:17:17.617 に答える
3

これを試して:

public void ShowAlert (string str)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder (this);
            alert.SetTitle (str);
            alert.SetPositiveButton ("OK", (senderAlert, args) => {
                // write your own set of instructions
                });

            //run the alert in UI thread to display in the screen
            RunOnUiThread (() => {
                alert.Show ();
            });
        }
于 2015-06-15T10:52:58.007 に答える