How To Catch Key Events While Soft Keyboard Is Open Android?
I know how to catch key events in my activity by overriding public boolean onKeyDown(int keyCode, KeyEvent event) The problem is when the soft keyboard is open this method is not
Solution 1:
Yes, when we speak about soft keyboard it's means that no so easy to use it. By the way methods that relate to soft keyboard take no expected result. For example:
@OverridepublicbooleanonKeyDown(int keyCode, KeyEvent event)
{
//do somethingreturnsuper.onKeyDown(keyCode, event);
}
The workaround that I've found is using of TextWatcher. Use this code for your application
YourEdit = (EditText) findViewById(R.id.YourEdit);
YourEdit.addTextChangedListener(new TextWatcher()
{
publicvoidafterTextChanged (Editable s)
{
//checking of TextWatcher functionality
Toast.makeText(mContext, "afterTextChanged", 3).show();
//do something
}
publicvoidbeforeTextChanged (CharSequence s, int start, int count, int after)
{
//checking of TextWatcher functionality
Toast.makeText(mContext, "beforeTextChanged", 3).show();
//do something
}
publicvoidonTextChanged (CharSequence s, int start, int before, int count)
{
//checking of TextWatcher functionality
Toast.makeText(mContext, "onTextChanged", 3).show();
//do something
}
});
These methods are called sequentially: beforeTextChanged, onTextChanged and afterTextChanged. You can catch any phase of text changing. Good luck!
Post a Comment for "How To Catch Key Events While Soft Keyboard Is Open Android?"