Reputation: 59
I have an EditText
, its taking inputs of letters and different symbols however not numbers. Additionally, I have set the EditText
on setOnKeyListener
to close the virtual keyboard by pressing Enter. Observed and found out that it failing to take numerical inputs due to the below code
Code for setting virtual keyboard to hide after pressing enter
durOnTreadmill.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_ENTER)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(durOnTreadmill.getWindowToken(), 0);
}
return true;
}
});
my EditText in XML
<EditText
android:id="@+id/durOnTreadmill"
android:layout_width="129dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="32dp"
android:inputType="text"
android:hint="hh:mm:ss" />
Where am I going wrong?
Upvotes: 4
Views: 934
Reputation: 8049
Copying my comment here:
You should only return true from onKey if you're handling the input. I.e., move the return true inside your if block and return false otherwise.
Upvotes: 2
Reputation: 7114
android:imeOptions="actionDone"
in you EditText xml will dissmiss the keyboard when the user hits enter and you say that it wont except numbers you have the input set to "text"
take this line out:
android:inputType="text"
Upvotes: 1