Using Xamarin and running in debug

I haven't been able to really play with Xamarin, Let me ask every one some thing. When I start debugging my app. and it runs and the eliminator. When it loads you should be able to test your app, Right. Are there any limits to the free version of Xamarin. I just can't get some of it to work. I don't mean errors in code. I just mean it doesn't work.

Look at the code below. The idea is that this should work. When the user clicks the save button. The Textview works out side the button method. This should create a SQLite database and insert a record into it. I did a search on my HDD for the file. and it was never created. So I'm a little lost here on what to do. Any one have some ideas.

`
TextView label1 = FindViewById (Resource.Id.labelView);
label1.Text = "Ready..."; //This works
btnSaveContact.Click += delegate {

            label1.Text = "Saving Record, Please Wait.";

            try
            {
            Contacts contact = new Contacts(-1, fullName, email, phone);
            DBContact.SaveContact(contact); // correct way
                label1.Text = "Saving Record Completed.";
            }
            catch(Exception ee)
            {
                label1.Text = "Saving Record Failed. : ";
            }

            Thread.Sleep(1000);
            label1.Text = ""; // This works

        };

The idea is to tell the user running the app what's going on. So I created a textView and just change the text on the textView. The 1st one works

label1.Text = "Ready..."; //This works

and the last one works all so

Thread.Sleep(1000); label1.Text = ""; // This works

How ever nothing else works. Nothing happens. ?

Posts

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    A could of thoughts:

    • The SaveContact method appears synchronous. If you are accessing a DB, I'd make this asynchronous (which could make your text labels start working, see below).
    • I don't believe the UX is going to get updated until the UX thread is released when setting the text property. Since your whole method is synchronous your not going to see the results until it exits so you just see it resetting the Text to ""; the last thing you did. I'd have to check to make sure this is true, but I suspect it is.
    • To give this type of status I might use a toast such as: Toast.MakeText(this, Resources.GetString(Resource.String.MessageChangesSaved), ToastLength.Short).Show(); or as is this case if you wanted a window that you can show status text on you use a ProgressDialog and then change/remove it on demand.
    • What is the purpose behind putting the UX thread to sleep. Isn't that going to just lock up your UX?

    I hope this helps.

    Thanks,

    Kevin

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    Wow, lost all my formatting on that last post.

  • bigjoe11abigjoe11a USMember

    Well the idea was to pause it, using the sleep(1000);, I use this before and it shouldn't lock up any thing. Can you please give me a sample of what your trying to do.

    Toast.MakeText(this, Resources.GetString(Resource.String.MessageChangesSaved), ToastLength.Short).Show();

    How can I use the above code to change the Text on a textView. I'm going to start looking for some videos on this option. Like the ProcessDialog there's nothing.

  • bigjoe11abigjoe11a USMember

    Kevin, I didn't find any thing useful on ProgressDialog(), How ever I did find some thing on Toast. How ever I get an error. It just tells me that some thing doesn't exist..

    `
    String toastMessage = "Ready...";
    Toast.MakeText(this, toastMessage, Toast.LENGTH_LONG).Show();

    `

    The code above is one same I did find. How ever it doesn't work. The compiler tells me that Toast.LENGTH_LONG doesn't exist. So any help from you would be great.

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    The Toast.LENGTH_LONG looks like an Android parameter, not the Xamarin Android API version. That should be more like ToastLength.Long.

    As for the Progress dialog you can probably do something like this:

    var dialog = ProgressDialog.Show(this, "Title", "Message");
    
    // Do some stuff
    
    dialog.Hide();
    

    Thanks,

    Kevin

  • bigjoe11abigjoe11a USMember

    Thanks Kevin, I fount out about the code for it last night. That's one thing that makes me mad is I can't get the code that I need that I'm working with. So ToastLength.Long is what I needed.

    As for the ProgressDialog. That's not what I was looking for. I'm looking for some thing like a Messagebox that's in C#. Messagebox.Show("","",Yes/No);..

    The idea is to show a message box and give the user choices. That way the code can deside what to do next.
    if(Messagebox msg = Messagebox.show("Program Name","Are you sure ?",Yes/No) == "Yes) { //Then it's ok to do some thing }

    That code is only a guess. It's been a while sense I done coding in C#.

    Thanks again
    Joe

  • DWestyDWesty USMember ✭✭

    If you are looking for Message Box type functionality you are looking for AlertDialog or Dialog fragment.

    http://docs.xamarin.com/guides/android/platform_features/fragments/part_3_-_specialized_fragment_classes

  • bigjoe11abigjoe11a USMember

    Thanks, the only one that came close was AlertDialog. How ever it too hard just to configure it. I fount a sample code. It's in a class and I don't want mine in a class. PLEASE does some one have some thing easy.

    public class AlertDialogFragment : DialogFragment { public override Dialog OnCreateDialog(Bundle savedInstanceState) { EventHandler<DialogClickEventArgs> okhandler; var builder = new AlertDialog.Builder(Activity) .SetMessage("This is my dialog.") .SetPositiveButton("Ok", (sender, args) => { // Do something when this button is clicked. }) .SetTitle("Custom Dialog"); return builder.Create(); } }

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    I'm afraid that's the gist of it. Do keep in mind that this is the Android SDK and it is the way Android works. Unfortunately, some things are not as clear and as simple as Windows Forms or WPF. You can think of Xamarin as a wrapper around the Android SDK. There's a little more to it than that, but at a 10,000 foot overview, think of it that way. Those folks at Google like to do things differently. Some times, it's pretty clever.

  • bigjoe11abigjoe11a USMember

    Thanks.

Sign In or Register to comment.