KeyListener not working as expected

by MB » Wed, 14 Apr 2010 03:03:50 GMT

Sponsored Links
 Hello All,
I am trying to implement a basic program.

I have a EditText view, and want to set a KeyListener to it.

Here is the code below.

myText.setOnKeyListener(new View.OnKeyListener() {
           public boolean onKey(View view,int keyCode,KeyEvent ke)
                        Log.d(TAG,nto on key;
               return true;

As it is returning true, the onKey method is called for all keys from
keyboard on screen, but the typed text does not appear on the EditText

If I return false, the onKey method is called for only meta keys like
Backspace (keyboard on screen),and the typed text does appear on the
EditText view.

I want to typed text on the EditText view, and work for all keys from
keyboard on screen(default Qwerty keyboard).

Where am I making mistake.

Could anyone pls let me know.



Other Threads

1. Fragments /Compatibility API Backstack Clearing Problem


I am rewriting an existing application to use the Fragments/Android
Compatibility API so that we can more easily add custom Tablet layouts
and I have come across a problem that I'm not sure how to solve. The
application has a custom tab-like control across the bottom which
represent different sections of the app. Touching each of these
sections loads a fragment that shows items in that section. Touching
one of those items (in our phone layout) loads another fragment that
shows the detail for that item and adds the transaction to the
backstack such that pressing back returns the user to the list of
items in the selected section.

The problem I am having is that I want the existing back stack to be
thrown out when a user clicks a new section at the bottom of the
screen and there doesn't seem to be any way to do that. Here is the
flow that creates the problem:

1. User touches section, which loads a list fragment.
2. User touches list item, which replaces the list fragment with a
detail fragment and adds the list fragment to the back stack.
3. User clicks a new section, which replaces the detail fragment with
a new list fragment.
4. User presses back, which causes the original list fragment to be
superimposed onto the new list fragment as android navigates backwards
through the back stack.

Ideally, I would like to be able to do something like
getFragmentManager().clearBackStack() in step 3, but this
functionality is not exposed in the API.

I can manually pop back through the back stack before showing the new
list, but that looks ugly to the user.
I could reload the activity passing the appropriate information to the
new instance to go to the right tab, but again, that looks ugly to the
I could hack the source and compile a custom version of the
compatibility library that implements a clearBackStack function, but
that makes it more difficult to move to pure honeycomb code later and
requires maintenance as new versions of the compatibility library are

Has anyone else run into this problem and found a more elegant
solution? I would sincerely appreciate any thoughts anyone has.

Josh Lefler


2. Buttons that create images?

Hi Everyone,

I'm writing an app that (ideally) will allow users to choose items
from various lists contained in menus (screen1>Menu Button>Choose
Category>Choose Item from List>Item appears on screen1).

What method would I implement in onClick to do this?

Thank you!


3. Android 1.5 with tablets compatibility

4. On Click method not working for buttons gotten by inflating the layout!

5. holographic theme without building against Android 3.0

6. OOT: Tes.... Tes....

7. Req: Java Developer