81475

Android onKey w/ virtual keyboard

I am catching keyboard events/presses using the onKey method:

public boolean onKey(View arg0, int arg1, KeyEvent arg2) { //do something return false; }

This fires off just fine for physical keyboard presses but it does not fire on virtual keyboard presses. Is there an event handler to handle virtual keyboard presses?

Answer1:

If it's an EditText, see if you can use a TextChangedListener instead.

myEditText.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { //do stuff } });

Answer2:

Virtual keypresses are delivered directly to the selected view, they don't propagate through parent views like hardware keypresses. Are you overriding onKey on something other than the EditText/List/Whatever that's getting keypresses? (the thing you click on to get the virtual keyboard)

Answer3:

myEditText.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) { //do stuff } });

Recommend

  • printk - showing in message log but not in terminal for any kernel log level
  • Can you set a background imaged to a PdfPTable when using iText
  • SQL Service Broker: Collecting data from distributed sources.
  • How to wait till webViewDidFinishLoad gets completed
  • Setting attributes of an EditText added dynamically in Android
  • TFS edit build log using custom activity
  • Capturing HTML Text Input Key press after key has been applied?
  • Update Search Results to Lazy Adapter in android
  • Number of nodes returned in MutationRecord.addedNodes nodelist (mutationObserver)
  • Linux over commit heuristic
  • How to fail Phing without triggering backtrace
  • Chrome breakpoint on radio doesn't fire
  • On which thread JavaFX change listeners are executed ?
  • Zend framework 2 : Add different authentication adapter for two different modules
  • setContentView() is not enough to switch between layouts?
  • Motorola barcode scanner SDK events C#
  • How do I Dispose a HttpResponseMessage in my Web Api Method?
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Detect when Facebook like button is clicked
  • AJAX Html Editor Extender upload image appearing blank
  • Django rest serializer Breaks when data exists
  • How to rebase a series of branches?
  • Android screen density dpi vs ppi
  • Launch Runnable Jar from Web Start
  • Azure Cloud Service Web Role web pages do not load
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to set my toolbar fixed while scrolling android
  • what is the difference between the asp.net mvc application and asp.net web application
  • How can I estimate amount of memory left with calling System.gc()?
  • Hits per day in Google Big Query
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Django query for large number of relationships
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?