One bug of the Android 2.x book: Professional Android 2 Application Development

The chap2 in the Android 2.x book “Professional Android 2 Application Development” gives a “TO-DO LIST EXAMPLE”, which will create a new to-do list Android application from scratch. There are 9 steps to create the to-do list application with using native Android View controls and the bug occurs on the final step:

“The final step to make this to-do list functional is to let users add new to-do items. Add an onKeyListener to the EditText that listens for a ‘‘D-pad center button’’ click before adding the contents of the EditText to the to-do list array and notifying the ArrayAdapter of the change. Then clear the EditText to prepare for another item.”

The added codes are bold:

myEditText.setOnKeyListener(new OnKeyListener() {
 public boolean onKey(View v, int keyCode, KeyEvent event) {
  if (event.getAction() == KeyEvent.ACTION_DOWN)
   if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
    todoItems.add(0, myEditText.getText().toString());
    return true;

If you can’t run this to-do list application as the Android project, maybe the bug occurred on the below line:

myEditText.setOnKeyListener(new OnKeyListener() {

You should modify this line to:

myEditText.setOnKeyListener(new View.OnKeyListener() {

then the problem maybe resolved.

Related Android Apps:

  1. Open Source Android Apps for Developers: Livingwallpaper (Living wallpaper application for the Google Android platform)
  2. Open Source Android Apps for Developers: StyloDownload (Android application for syncing Google Reader starred items to the media player)
  3. Android 2.x books for developers
  4. Open Source Android Apps for Developers: Azilink (usb tethering application for android)
  5. Android books for developers:part one
  6. Open Source Android Apps for Developers: Diskusage (Diskusage application for android phone)
  7. Open Source Android Apps for Developers: Appicker
  8. Android books for Users: Google on the Go
  9. Android SDK Tools Overview
  10. Open Source Android Apps for Developers: Androidscreencast