View Single Post
  #1 (permalink)  
Old December 30th, 2011, 08:53 AM
harrison57 harrison57 is offline
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 To Do List setOnKeyListener Problem


I tried to execute the code mentioned in the book, but i keep getting the error

Multiple markers at this line
- The method setOnKeyListener(View.OnKeyListener) in the type View is not applicable for the arguments
(new DialogInterface.OnKeyListener(){})
- The type new DialogInterface.OnKeyListener(){} must implement the inherited abstract method
DialogInterface.OnKeyListener.onKey(DialogInterfac e, int, KeyEvent)

package com.androiddevelopment.todolist;

import java.util.ArrayList;

import android.content.DialogInterface.OnKeyListener;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class ToDoListActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
ListView myListView = (ListView)findViewById(;
final EditText myEditText=(EditText)findViewById( ;

final ArrayList<String> todoItems = new ArrayList<String>();

final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,

// Bind the array adapter to the listview

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;
return false;

Reply With Quote