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());
    aa.notifyDataSetChanged();
    myEditText.setText(“”);
    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. Cute Android Apps for Users: Aldiko Book Reader
  2. Open Source Android Apps for Developers: StyloDownload (Android application for syncing Google Reader starred items to the media player)
  3. Open Source Android Apps for Developers: Livingwallpaper (Living wallpaper application for the Google Android platform)
  4. Open Source Android Apps for Developers: Azilink (usb tethering application for android)
  5. Open Source Android Apps for Developers: Diskusage (Diskusage application for android phone)
  6. Android books for developers:part one
  7. Android books for Users: Google on the Go
  8. Open Source Android Apps for Developers: FBReaderJ (An e-book reader for Google Android platform)
  9. Cute Android Apps for Users: How to Draw cartoons
  10. Android 2.x books for developers