Android Development 24

Android Dialog BoxesIn this part of my Android Development tutorial I will cover how to use Android Dialog Boxes. We’ll cover how to design their layouts, how to call for them to open and how to send data from dialog boxes to other fragments and activities using putSerializable and getSerializableExtra.

Because I’ll be working specifically with birth dates we’ll also take a look at the Date, Calendar and GregorianCalendar. All of the code can be found after the video to help you better understand.

If you like videos like this, it helps to tell Google+ with a click here [googleplusone]

Code from the Video

The whole package is here ADT 24 Census App

Contact.java

dialog_date.xml

strings.xml

DateDialogFragment.java

ContactFragment.java

26 thoughts on “Android Development 24”

  1. Hey Derek,

    If I wanted to save the changes I make to the contacts, how would I do that?

    Everytime I run the app it restores to the default values.

    I guess my question is how to save the data and restore.

    Thanks.

  2. Hi Derek. This is regarding a file in the download zip.

    in CensusApp.java

    line 30: ContactFragment()
    line 31: return ContactFragment.newContactFragment(contactIdNumber);

    I’m having some trouble figuring out the reason for line 30. Is that a typo?

    Thanks

    1. Hi Gerard,

      I’m not sure what line you are referring to. I just looked at the code. i think you may be referring to something that was part of a commented out line. Sorry about the confusion.

  3. Hi, Derek

    I execute the sample code, and it jump out error MSG “Unforturnlly, Census app has stopped” when I click on a personal data.

    Catlog warm showup:
    01-03 07:01:00.004: E/AndroidRuntime(3205): FATAL EXCEPTION: main
    01-03 07:01:00.004: E/AndroidRuntime(3205): java.lang.NullPointerException
    01-03 07:01:00.004: E/AndroidRuntime(3205): at com.newthinktank.censusapp.ContactFragment.onCreateView(ContactFragment.java:178)
    01-03 07:01:00.004: E/AndroidRuntime(3205): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)

      1. Sorry about not saying clearly, I do use package now, and I did try replace ContactFragment.java code from web also can’t work.

    1. I have the same problem. I use a Samsung Galaxy 10.1 tablet running Android 3.1 but my project has Android 4.3. That may be significant and it may ressemble to the situation of yopur setup Sarah.

    2. After some more investigations I’ve found that the same problem occur when I set it to 2.3.3 and 3.1 in the eclipse project. The error message is

      W/ResourceType(10609): Failure getting entry for 0x7f06000b (t=5 e=11) in package 0 (error -75)
      W/Resources(10609): Converting to string: TypedValue{t=0x1/d=0x7f06000b a=-1 r=0x7f06000b}
      D/AndroidRuntime(10609): Shutting down VM
      W/dalvikvm(10609): threadid=1: thread exiting with uncaught exception (group=0x402b1760)
      E/AndroidRuntime(10609): FATAL EXCEPTION: main
      E/AndroidRuntime(10609): java.lang.NullPointerException
      E/AndroidRuntime(10609): at com.newthinktank.censusapp.ContactFragment.onCreateView(ContactFragment.java:176)
      E/AndroidRuntime(10609): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
      E/AndroidRuntime(10609): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)

      The class R is indeed regenerated. I removed it and rebuilt it. The R.string inner class has the following

      public static final int contact_phone_number_hint=0x7f06000b;

      1. Any time you get R file errors it is best to delete the R file and then Project -> Clean. You may also want to try and Help -> Check for Updates. I hope that helps.

        1. Hi Derek 🙂

          I received the same java.lang.NullPointerException while running CensusApp (from the package) on my device and I found that it occurred only when device is in landscape mode and the ContactFragment fragment is used.
          After trying for a while to find the problem, I saw that you never added the new EditText and Checkbox to the landscape XML layout. I fixed it and the app worked perfectly 😀

          Thanks a lot for all your great tutorials! I am an electronic engineering student from South Africa and I have to do a final year project next semester where in I am required to write an Android app to communicate with another device that I have to design and build. Your tutorials have really helped me a lot, thanks for all your effort!!

          1. Hi Jaco,

            Thank you for posting your fix. I’m very happy that you enjoy the videos. You’re very welcome 🙂 I wish you all the best on your final project.

  4. Hi Derek,

    Just wondering if you are going to finish this excellent tutorial? In part 18 of the Android Development you said you would take us step by step through the creation of a Big App that included adding people to a database, taking pictures and using fragment in a bunch of different ways. The app looked awesome and was the exact thing I’ve been looking for all over the internet to get me started on an app I’ve been thinking of doing for months.

    Please don’t think I’m criticising your tutorial. I am most certainly not as it’s taught me so much and been delivered in a highly professional and easily understood manner, it’s just it promised so much but has just stopped mid app.

    I understand that other projects and interests may have taken over your time but it would be great to see how to finish this app off.

    Thanks in any case for your time and efforts as they are hugely appreciated.

    Thanks in advance.

  5. 🙂 awwwwww, no more vidss.

    I’ll subscribe (YT) in hope you find the time to get back to this. AWESOME tuts, seriously. It was incredibly helpful to go through a multi-part app like this. Thanks Derek!

    (Gobbled tuts 18-24 all in one sitting xD, simply outstanding!)

    1. (oh and just FYI – Bug Report:

      There is a bug with main view (ContactViewPager.java) not updating edited record information until the app is reopened… Data points are recorded correctly, just not updating list_item_contacts listed in main view.

      Cheers,)

      Thanks, thanks, thanks, and thanks again for the tuts!

      : )

    2. Thank you very much 🙂 I will get back to regular Android java development. I decided it would be helpful to take a look at App Inventor though because so much can be done with it. Then I’ll come back and dive into Java again.

  6. Hi Derek,
    Im not yet in this video, but in a couple of days i will be. So i wonder, where to go from here?

Leave a Reply

Your email address will not be published. Required fields are marked *