Android Development 12

Android SQLiteIn this tutorial I’ll continue making my Android SQLite Address Book app. I hope this code is useful enough to use as a cheat sheet when you need to use an SQLite database in Android.

I cover a ton of topics: How to Create a SQLite Database and Tables, How to Issue Queries, How to Insert Data, How to Update Data, How to Delete Data, SQLiteOpenHelper, execSQL, SQLiteDatabase, ContentValues, rawQuery, Cursor, and more. The code below will help.

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

Code From the Video

DBTools.java

25 thoughts on “Android Development 12”

  1. Hello Derek. Thanks for the beautiful tutorials.

    Just want to pay your attention to a small issue about auto_complete in eclipse. When you want to type for example android:textColor="" you can start from te and press ctrl+space and it will give a list of usefull suggestions.

    Another example: android:text="@string/add_contact
    – Type te then ctrl+space for android:text=”"
    – Type @s then ctrl+space for @string/
    – Type ad then ctrl+space for add_contact

    This is for windows. I don’t know what is the equivalent in Mac.

    Thank you.

    1. There are many short-cuts. Just few more:
      For android:layout_weight="1"
      Just type w then Ctrl+Space and it will give you a list of suggestions,so that you can easily pick it out.

      For android:padding="@dimen/pendding_5dp"/>
      – Type pa then Ctrl+Space for android:padding=""
      – Type @d then Ctrl+Space for @dimen/
      – Type p then Ctrl+Space for pendding_5dp

      Hope that help you instead of jumping from place to place to copy things, or jump to Graphical layout just for the purpose of searching for a string value.

  2. Wow, the range of things you are covering with this ContactsApp is great, learning so much in just this 5 part series alone!
    I’m a bit of a slow learner but the way you present this is brilliant. Derek, thanks x 100 for the wealth of information on your site, and for sharing your expertise!

  3. One more question: why do we need to close the database after an insert operation but not after a delete?

    -Jay

  4. Hi Derek, I managed to solve the problems I had with the interface and the positioning of the buttons. I just uninstalled and jdk for Eclipes reinstalled following the tutorial Install Android Development Tools. However now I have a problem, for the tutorial 12 I am not able to make a file that is named DBTools.java. Will I need to install additional plug-in?

  5. Great tutorials, I can give you another shortcut tip.
    When you have to import any library just press: CTRL + SHIFT + O(the letter), and if you want to format and indent your code just press: CTRL + SHIFT + F.
    Have a great day!

    1. Thank you for the tips. I know about the shortcuts, but I decided not to use them in tutorials because I can never trust that anyone else knows them. I hope that makes sense πŸ™‚

  6. Hi Derek,

    Have you worked on using a pre-populated database e.g. android.db is your database name. You created all the tables and inserted data using SQLite Database browser or from command line. You saved it to assets/android.db directory. From there, your program can copy it over to android database location /data/data//database/.

    I tried the solution from the following article, however, I was not successful. It always fails because a database table already exists. Do you know how to do this? Please share your solution.

    http://blog.softeq.com/2012/12/using-pre-populated-sqlite-database-in.html

    Thanks a lot!

  7. How do you call a database you’ve already created? And where do you put it in your app? Thank you in advance.

  8. Hi Derek,

    Thanks a lot for these tutorials, they are really much more helpful than any book on the topic that i have read. I tend to get bored very fast with java books, they simply contain to much nonsense between the lines. Actually, the only good programming book that i have read were about Phyton (Python Programming for the Absolute Beginner). In each chapter you creat a program from start to finish, with no unanswered questions after the chapter. Similar to what you are doing with your tutorials! Ive been looking for such a java book for years now, and 6 java books later i found your tutorials by chance. The only regret is that i were trying so long with the books.

    Keep up the good work!

  9. Well I see I didn’t got it completely but why did you created DBTools.java in other project than the Address Book Application? Can I create it in the later?

    Tip : Do add the next video page link on your website. For example – there should be a link on this page pointing to Part 13 page.

Leave a Reply

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