Posts in the “android” category

How to create SQLite comments

SQLite FAQ: How do I create comments in SQLite?

SQLite lets you create comments using two different constructs, either two hyphens in sequence ("--"), or the "/.../" C-style comments. Here are examples of each approach, with the SQLite comments preceding the two database table definitions:

How to create a SQLite database

SQLite database FAQ: How do I create a SQLite database?

Creating a new database in SQLite is so easy, it's amazing. Once you have SQLite installed and your PATH set up properly, from your Unix or DOS shell, just issue a SQLite command like this:

Show SQLite tables from the Android command line shell (adb)

Android/SQLite FAQ: How do I show a list of SQLite database tables from the Android command line (adb shell)?

You can show a list of SQLite tables by starting the Android adb shell (command line tool), and then properly invoking the sqlite3 command. Here's an example of how this works, with comments shown before each command:

SQLite backup: How to dump a SQLite database

SQLite dump/backup FAQ: How do I backup (dump) a SQLite database (or database table)?

"How to make a backup of a SQLite database?" is a really interesting question. Because a SQLite database is really just a file, if you truly want to make a backup of that database, it can be as simple as copying that file to a backup location.

But there is more to the story ...

[toc hidden:1]

SQLite CSV import examples

SQLite CSV FAQ: How do I import a CSV file into a SQLite database table?

If you’re not using an autoincrement (primary key) field in your database table, importing CSV file data into a SQLite database is straightforward, though you may have to do some work to clean up your data first. Let’s take a look at how this works.

A SQLite CSV import example

As a first example, assume that I have a SQLite database table defined like this:

[toc hidden:1]

SQLite: How to get the “autoincrement” value from the last insert

SQLite autoincrement FAQ: How do I get the autoincrement value from my last SQLite INSERT command?

You can get the integer value of the primary key field from the last insert into an autoincrement field using a SQLite function named last_insert_rowid(), as shown in the example below.

SQLite: Default a datetime field to the current time (now)

SQLite FAQ: How do I default a SQLite datetime field to the current date and time? (i.e., how do I default it to now?)

Just use the SQLite current_timestamp function, like this:

last_updated datetime default current_timestamp

In a more complete create table example I just used on an Android project, this looks like this:

What I learned today, February 23, 2015 (mostly Android)

This is a collection of notes about what I learned today, February 23, 2015. Most of it is about Android.

I need to refresh my cursor data set before calling notifyDataSetChanged

When (a) adding, editing, or deleting items in a ListView and (b) using a CursorAdapter, I need to update my cursor object before calling notifyDataSetChanged.

I created this method, which I call from my fragment’s onResume method:

SQLite alter table syntax examples

SQLite FAQ: Can you show me how the SQLite ALTER TABLE syntax works?

At the time of this writing you can use the SQLite ALTER TABLE syntax for two purposes:

  1. Add a column to the end of an existing SQLite database table
  2. Change the name of a database table.

For other changes you'll have to follow some workaround procedures (discussed below).

[toc hidden:1]

My Google Nexus 9 review (making the switch from iPad to Android)

My old iPad 2 was, well, old, and it’s slow speed was driving me crazy. So I decided to buy a new tablet, but when I made that decision I also decided to look around, and in short, I eventually decided to buy a Google Nexus 9. After a few days with it, here’s my review of the Nexus 9.

The Nexus 9 unboxing experience

The Nexus 9 unboxing experience was a non-experience. The Nexus 9 comes in a simple, unattractive box, and there’s nothing special about any part of the unboxing experience.

[toc hidden:1]

Android ActionBar example: How to create an options menu item

As Android programming goes, creating an options menu item/button in the Android ActionBar is fairly straightforward. In this brief tutorial I’ll demonstrate all of the steps needed to add a new menu item to the action bar.

1) Define the view/layout

The first step is to declare what the menu “view” is going to look like. This is very similar to defining other Android views, you do it with an XML layout file.

How to show an HTML string in an Android TextView

[toc]

Filed under “What I learned about Android today,” it turns out that you can display an HTML string in an Android TextView. However, this approach has major limitations, and you’ll probably want to display your HTML in a WebView instead.

Skipping past that issue for a few moments ... if you want to try to display an HTML string in a TextView, you need to use the Android Html.fromHtml() method, as shown in this code: