Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 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
  #1 (permalink)  
Old January 11th, 2014, 10:21 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 ToDoList Part 1

Hi guys, I've been following step by step the code to the first example of the ToDoList App but, even though it compiles perfectly and run on my device, it seems that the keypress event is never reached.

This is the code:

myEditText.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)||
(keyCode == KeyEvent.KEYCODE_ENTER)){
todoItems.add(0, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
return true;
}
}
return false;
}
});

I'm using Android Studio instead of Eclipse, maybe it has something to do with this error, or maybe the code in the example is too old and some parts are deprecated already...

Thanks in advance...
  #2 (permalink)  
Old January 19th, 2014, 06:01 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

can u upload the full code?
  #3 (permalink)  
Old March 7th, 2014, 05:07 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is a solution mentioned in this post by NeedAName:


1. I needed to make the EditText accept single line input only. I did this in the <EditText> node (I also set the button to "Done"):
android:singLine="true"
android:imeOptions="actionDone"

2. Next, in the onCreate() I added the following after the "myListView.setAdapter(aa);" line:

// Catch the "done" button on softkeyboard
myEditText.setOnEditorActionListener(new EditText.OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE){
//done Clicked
addTextToListView(myEditText, todoItems, aa);
return true;
}
return false;
}
});

Try it.

Cheers MF


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 ToDoList Database michael_mctear BOOK: Professional Android 4 Application Development 11 December 18th, 2013 08:34 AM
Chapter 4 ToDoList Problem cythe BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 6 June 15th, 2011 09:53 PM
ToDoList Chapter 5 Line painting rich833 BOOK: Professional Android 2 Application Development 0 April 27th, 2011 09:28 AM
Chapter 2 - ToDoList Example srkrkalyan BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 January 22nd, 2011 01:09 PM
chapter 2 todolist kdpohl1 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 5 July 16th, 2010 03:59 AM





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