Wrox Programmer Forums
|
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
 
Old December 23rd, 2012, 02:21 AM
Registered User
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Soft keyboard

Hi,

I'm trying to do the Chapter 4 exercise with the simple EditText and ListView controls. However, my emulator isn't catching the "Enter" key of the soft keyboard.

If I use the D button then the program catches the "myEditText.setOnKeyListener", but the soft keyboard does not capture it.

I am using an emulator set to target Android 4.2 on a Nexus S.

How can I catch the "enter" event from the soft keyboard?
 
Old December 24th, 2012, 01:55 PM
Registered User
 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found an answer to my own question. I had to do a couple of things:

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



Special thanks to myself for the answer. You're welcome, myself!

And if anyone wants to add that to the next version of the book then please send me the commission or royalties via PayPal or cheque.
 
Old January 23rd, 2013, 07:37 PM
Registered User
 
Join Date: Aug 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same problem. Further reading reveals that View.OnKeyListener will ONLY respond to hardware keys, not the soft on-screen keypad. If you set the emulator to assume a hardware keyboard, then your pc keys WILL trigger the listener, but the diagram on page 114 shows soft keyboard is active & I took this to mean that the soft RETURN would be admissible, but clearly not. I assume that for this example the emulator has to be setup to mimic a hardware D-Pad & Return key.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview and Soft Keyboard norwell BOOK: Beginning Android Application Development 1 February 15th, 2012 01:24 PM
What soft do i need to use xslt? crissty XSLT 1 November 22nd, 2007 07:00 AM
very soft sound sentme_mail Flash (all versions) 0 November 15th, 2004 01:00 AM





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