Wrox Programmer Forums
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 31st, 2011, 05:04 AM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 To Do List setOnKeyListener Problem

Hi,

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.app.Activity;
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. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText=(EditText)findViewById(R.id.myEditText) ;

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

final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
todoItems);

// Bind the array adapter to the listview
myListView.setAdapter(aa);

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

}

The code is written in eclipse with ADT plugin.
 
Old January 7th, 2012, 06:46 PM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try
import android.view.View.OnKeyListener;

instead of
import android.content.DialogInterface.OnKeyListener;
 
Old January 13th, 2012, 11:42 AM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot, it worked





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 To Do List setOnKeyListener Problem harrison57 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 1 November 1st, 2012 07:35 AM
To Do list chapter one WaJMHome BOOK: Professional Android 2 Application Development 8 November 14th, 2011 10:12 AM
Problem: Chapter 7 "Saving Your To-Do List" (Page 218) DrGaribaldi BOOK: Professional Android 2 Application Development 2 March 21st, 2011 01:53 AM
Chapter 6 To Do List EricTapia BOOK: Professional Android 2 Application Development 0 April 14th, 2010 01:40 AM
Chapter 19 Address List problem srgibson99 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 June 15th, 2005 05:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.