Android Notebook, page 2

There’s a tab character in the Notepadv1.java sample file. Tab characters should not be used.

Android has an embedded SQL database, Useful.

I wish XML layout files would open in XML view by default rather than layout view.

The tutorial is a little flaky with XML terms. It’s an XML declaration, not an “XML header”.

Some things that look like XPath expressions at first glance, aren’t.

Trying to read a tutorial in one window and use Eclipse in the other is painful. Maybe if I put my laptop on the desk?

The tutorial’s naming conventions aren’t following Java standards. Someone likes to put “m” in front of all the instance fields.

XML localization and UI construction: nice.


There’s something about GUIs that just makes people fill methods with illegible arguments:

menu.add(0, INSERT_ID, 0, R.string.menu_insert);

It isn’t obvious, but that’s four ints in a row. I guarantee a lot of bugs when the argument order is swapped. In fact, perhaps I’m noticing a general design principle here:

Do not design method signatures such that more than two values of the same type must be passed, especially in consecutive positions.

A more fluent interface might be helpful here, as would a language (not Java) which allowed named argument lists. Hmm, it also occurs to me that this is another reason to prefer GUI construction in XML instead of code. Each value is identified by name, not by positions. Sure it’s verbose and redundant, but humans need verbosity and redundancy to help us out.


OK. This is weird. This compiles:

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case INSERT_ID:
                createNote();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

But this does not:

    public boolean onOptionsItemSelected(MenuItem item) {
        switch item.getItemId() {
            case INSERT_ID:
                createNote();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

Why are the parentheses necessary? Oh wait. I’ve been writing too much Haskell lately. Parentheses are always necessary for switch in Java, just like for if and while.


I wish Eclipse had a “Run as Android Application…” menu item in the context menu. Oh wait, I have to select the Project first. I can’t just do it from a source file.

Leave a Reply