Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 23rd, 2012, 02:21 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
  #2 (permalink)  
Old December 24th, 2012, 01:55 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #3 (permalink)  
Old January 23rd, 2013, 07:37 PM
Registered User
Points: 9, Level: 1
Points: 9, Level: 1 Points: 9, Level: 1 Points: 9, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: , , .
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.