Welcome to part 13 of my Android Development Tutorial! In this tutorial I will continue building the Android Address Book App previously covered in parts 10, 11 and 12. If you haven’t seen them, check them out first.
Specifically in this tutorial I will create the Java that will power the ListView for the Main Activity and I’ll also cover the New Contact code needed to add a contact to the database. All of the heavily commented code after the video should help make everything understandable.
If you like videos like this, it helps to tell Google+ with a click here [googleplusone]
Code From the Video
MainActivity.java
NewContact.java
Derek, thank you so much for all of these tutorials. By far the clearest available. If I wanted to also include an ImageView in the list layout, say, a contact photo, and I was storing these pngs in a drawable folder, how would I alter the adapter?
I was thinking of having a column in the database which contained a string of the filename. Now just to connect it…
You’re very welcome 🙂 I’ll cover adding video, images, animations, etc. as soon as possible. My next Android video will be on fragments and nice interfaces. I’ll get it up as soon as possible
Best tutorial in android available in hundreds of tutorial in Youtube . I am new in android but just watching tutorials and code i am now able to start code in JUST 3 Days ..
Thank you 🙂 I’m very happy to hear that I was able to help. Many more Android tutorials are coming
Hi Derek,
What if my table has multiple datatypes? How would the hashmap be different then? FOr e.g. my table has INTEGER AND TEXT fields that I need to insert to db. Can you please advise?
Thanks!
You could store everything as a string in the hash map and then cast to the needed data types. Does that help?
I run StockQuotes no problem with my Bionic device but I cannot get the EditContact.java to run. Would you see inside my logCat and direct me to fix? Thx in advance.
09-09 10:17:54.608: E/Trace(22126): error opening trace file: No such file or directory (2)
09-09 10:17:54.694: E/AndroidRuntime(22126): FATAL EXCEPTION: main
09-09 10:17:54.694: E/AndroidRuntime(22126): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.theratutoring.contactsapp/com.theratutoring.contactsapp.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2136)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2174)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread.access$700(ActivityThread.java:141)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1267)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.os.Looper.loop(Looper.java:137)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread.main(ActivityThread.java:5059)
09-09 10:17:54.694: E/AndroidRuntime(22126): at java.lang.reflect.Method.invokeNative(Native Method)
09-09 10:17:54.694: E/AndroidRuntime(22126): at java.lang.reflect.Method.invoke(Method.java:511)
09-09 10:17:54.694: E/AndroidRuntime(22126): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
09-09 10:17:54.694: E/AndroidRuntime(22126): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
09-09 10:17:54.694: E/AndroidRuntime(22126): at dalvik.system.NativeStart.main(Native Method)
09-09 10:17:54.694: E/AndroidRuntime(22126): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
09-09 10:17:54.694: E/AndroidRuntime(22126): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:263)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.Activity.setContentView(Activity.java:1893)
09-09 10:17:54.694: E/AndroidRuntime(22126): at com.theratutoring.contactsapp.MainActivity.onCreate(MainActivity.java:44)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.Activity.performCreate(Activity.java:5058)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
09-09 10:17:54.694: E/AndroidRuntime(22126): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
09-09 10:17:54.694: E/AndroidRuntime(22126): … 11 more
Is it merely adding the list to R and if yes, what is best approach?
It looks like the R file isn’t auto updating. Make sure you don’t have any import R imports in any of your java files in src. If you do delete them and then restart Eclipse. You may also want to check for Updates (Help -> Check for Updates)
hello there, I am also running into the same problem. My application failed to start. Please share if you got it solved. Thanks
hello there, I was also running into the same kind of error, only that my app wont even start at all. But it throws the same log errors as yours. Please kindly help if you have found the solution to it. Thanks
My opinion is that when you populate a list with data from a SQLite database, the simplest is to extend a cursor adapter, with bindView and NewView, in bindView you don’t need to care for recycling of layout inflation…
Thanks for the input 🙂
hi Banas there’s problem with setListAdapter. Could you please help me with this problem. Thanks
What errors are you getting in the LogCat panel?
Hello. I have recently started to learn android development (and programming in general) and your guide series helped me a lot.
Right now I am trying to create a endless listview (listview expands as you scroll down to avoid load time) for a large set of data. After some research, I gathered that I should use a CursorAdapter and extends commonware’s endlessadapter.
Am I on the right track? I am not expecting a long answer, but I just don’t want to spent a lot of time looking for the wrong thing 🙂
Helpfully you see this, and thank you!
Hello,
Have you seen this tutorial on Android ListView? I think that is what you are looking for.
I hope that helps 🙂
Derek
Thank you. I’ll start watching that part of the tutorial 🙂
Hello Derek,
Firstly, I want to thank for this great tutorials,
Secondly, I have problem I am copy your code of mainActivity and activity_main.xml but in the catlog the following error arise:
12-04 22:29:45.982: E/AndroidRuntime(2462): cannot open customer xml file
and when I make a debugging the run stop at this line of code
setContentView(R.layout.activity_main);
Please I need Your Help.
Hello,
I have the whole package for the Android App here. Tell me if you have any problems with it.
Hi Derek!
Just wanted to start off by saying great tutorials and am so grateful for the time you take to make them and also answer questions.
I have a question for you, I’ve googled and googled and searched and haven’t been able to find an answer.
I’m designing and app that has a stopwatch aspect to it. Now my question is regarding storing the values of the splits.
I.e. I don’t know how many splits a user needs because it varies from race to race.
I’ve thought of 2 solutions:
1. make 100 columns and hope the user doesn’t need more than 98 splits/race. (although I think this would make it too bulky esp. if they only need 1 or 2 splits).
2. make 2 tables and reference the second table splits. 1 with (|id|finaltime|splitsrefnum|) and the other with (|split|) so if it had 5 splits, it would have 5 rows. etc…
I believe #2 is foreignkeys?
You don’t need waste your time and write code, I’d just appreciate a push in the right direction so I could know what the “right way” of doing this is.
Thanks again!
Hi Miguel,
Why not save the data to a file and then you won’t need to worry about defining a maximum size. Anytime I need to store a ton of information and I want to keep it organized I use SQLite. I have tutorials on both on my site. I hope that helps 🙂
hi Derek, thank you for your great effort,
and i have a little question, i wanna make my first android app 🙂 and i have a small idea i wanna make “Taking Notes app” just to apply what i learned from you, but i have no idea about what my app should looks like, and if you have any idea what the app should looks like plz tell me and i will be grateful to you, thank you in advance and thank you for your great effort again 🙂
Thank you 🙂 I’m going to be making more Java Android videos very soon. I’ll cover everything I didn’t cover before. I’ll spend a lot of time on interfaces.
hi, thanks for ur tutorial…
but can i know how to add a dialog box and show the details confirmation whether to save or cancel before save.?
thanks
I’ll be making a new Android tutorial in a week or 2. I’ll cover everything then.