EditText not accepting numbers - android

A client is testing an Android app I made for them and they are using a tablet. They say that they can't enter numbers in an EditText, but it seems to work on my phone. What could be a reason or this?
Here is the code for a particular EditText:
pWord = (EditText)findViewById(R.id.passwordsignin);
y = false;
signIn = (Button) findViewById(R.id.signin);
pWord.setOnKeyListener(new OnKeyListener(){
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER){
y = true;
new RegisterDeviceAsynctask().execute();
}
return true;
}
});
and the XML:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/passwordsignin"
android:layout_below="#+id/emailsignin"
android:layout_centerHorizontal="true"
android:hint="Password"
android:layout_marginTop="10dip"/>
Edit: The issue ended when I ended the setOnKeyListener code. Any idea why this could be?

tell your client to use two types of text, for example: android:inputType= "typeOne|typeTwo" ... change typeOne and Two and use Log to print real output.

Some suggestions:
1. Your android:inputType="textPassword" will not let anyone see what is being entered. Try changing the android:inputType="text" so you can see if the expected character is being entered. That will let you debug the issue. It is possible the user is mistyping.
2. Try logging the password or putting it into a Toast so the user can see what they typed.
The above suggestions are for the debug period only. For release you don't want to have those in place. Your users should probably change their password after the debug period (or before, to a temporary password, and then change it back to the real password).

Try this
android:inputType="TYPE_TEXT_VARIATION_PASSWORD|TYPE_NUMBER_VARIATION_PASSWORD"
This will ensure that an appropriate keyboard/input method is selected for it (this can be dependent on the actual hardware manufacturer).
If that doesn't work, ask that they separate the physical keyboard from the tablet, to make the software keyboard come up.
If that doesn't work, see if they don't have a third party custom keyboard installed. Not only we have different hardware manufacturers, but since people can install their own keyboards from Google Play, that's another possibility.
If that doesn't work, ask them to take a screenshot of the keyboard they're getting on it, anonymize the screenshot the best way you can, and then post it on here in your question.

Just change youe code a bit:
pWord = (EditText)findViewById(R.id.passwordsignin);
y = false;
signIn = (Button) findViewById(R.id.signin);
pWord.setOnKeyListener(new OnKeyListener(){
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER){
y = true;
new RegisterDeviceAsynctask().execute();
return true;
}
return false;
}
});

just use this code as your SetOnKeyListener
if (keycode==keyevent.keyback)
{
...
}
else
{
return false;
}

Related

Space Key event behaviour on Numeric Input field?

I created two EditText with "android:inputType="number" property.
here I am using hardware Keyboard, so when I perform Space Key event on textField, focus control directly shift from editText view to some other random view of screen. In normal text field type it took it as an another character, that's fine.
Any one have idea how can use Space key event to retain focus on same field.
Using editText.setInputType(InputType.TYPE_CLASS_NUMBER) may probably solve your problem.
Change/Add your EditText Property with android:imeOptions="actionNext" like as follows
<EditText
android:id="#+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text" />
Or with android:imeOptions="actionNone" for default behavior of EditText
<EditText
android:id="#+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNone"
android:inputType="text" />
So it looks like your problem doesn't have to do with the 'input' type of your EditText, but rather the key press events coming from the keyboard....
So 'hopefully' this should fix your problem for you (by 'skipping over' the 'next' event from the 'space' button being pressed.)
// do for both EditText(s)
editText1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
log.d("main","KeyPress:"+ actionID);
if (event != null ) { log.d("main","KeyPress:" + event.getKeyCode() ); }
if ( actionId == EditorInfo.IME_ACTION_NEXT) {
// do 'nothing' or 'add a space' if you want that
return true;
}
return false;
}
});
This is likely what is happening (hard to tell without your XML)
So I found something that should help you figure out the pattern + possibly lead to solving it... from https://stackoverflow.com/a/17990096
if there is a android:nextFocus.... setting in your XML (or equivalent in code) and/or the physical keyboard 'space' is also signalling IME_ACTION_NEXT (or another IME action similar to it)
If the EditorInfo.IME_ACTION_NEXT isn't the IME action that is causing your problems, then you can try this... to determine WHAT is.
from: https://stackoverflow.com/a/4171427
if you have PHYSICAL keyboard you can use to detect keyDown events and handle them appropriately,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
log.d("main","KeyPress:" + keyCode);
if (event != null ) { log.d("main","KeyPress:" + event.getKeyCode() ); }
// if you want to 'handle' the keyPess here, best to use switch like below
// switch (keyCode) {
// case KeyEvent.KEYCODE_A:
// {
// //your Action code
// return true;
// }
/// }
return super.onKeyDown(keyCode, event);
}
BUT... if you have software keyboard You need to use addTextChangedListener/TextWatcher Because the physical key press is 'eaten' by the EditText (from what I saw in another post, but seems to be correct from my testing.)
mMyEditText.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
/*This method is called to notify you that, within s, the count characters beginning at start are about to be replaced by new text with length after. It is an error to attempt to make changes to s from this callback.*/
}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
);
You can override what the EditText does when a 'space' is entered.
This seems pretty easy when in 'software keyboard', but physical keyboard seems to be a bit more difficult.
https://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html
Similar to this question (but 'space' instead of 'enter') Android - Handle "Enter" in an EditText
This could help you determine the 'pattern' of the focus being changed. if it is random or not (most likely -not- random, but possibly 'interesting' to look into)
http://developer.android.com/reference/android/view/View.OnFocusChangeListener.html
// try this to see
View.OnFocusChangeListener changeListener = new View.OnFocusChangeListener()
{
#Override
public void onFocusChange(View v, boolean hasFocus) {
log.d("YourClassName", "FocusChanged" + hasFocus)
}
};
EditText1.setOnFocusChangeListener(changeListener);
EditText2.setOnFocusChangeListener(changeListener);
Button.setOnFocusChangeListener(changeListener);
// ... etc... (add to views to see if there is pattern)

Monodroid - EditText input method won't accept numbers

I am having some very strange problems with the EditText control in Mono for Android. My solution is targeting 2.3 and I am debugging on a T Mobile VivaCity. Here is my AXML for the EditText
<EditText
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ctl_searchText" />
When I show the View containing the EditText the keyboard automatically appears, this is not a problem. The problem is I can't enter any numbers by tapping the numbers on the keyboard, the only way I can get a number to show in the text field is if I hold the key down and chose the number from a context menu. Although once I've entered a number in using this method I'm then not able to delete it. I've tried all sorts of input methods and had a look for similar issues in SO to no avail. Does this sound like an issue with the device? Or is there something glaringly obvious I'm not doing in the code/AXML?
== EDIT ==
I think I've narrowed the problem down, it has something to do with the KeyPress event handler used on the EditText. As the EditText represents a search field I have added the attribute android:singleLine="true" to stop the return key from adding an extra line and instead say "Done". When I add a KeyPress event handler to the control this is when it stops me from entering numbers, but without the handler it begins to function normally again. Here is what I have:
<EditText
android:id="#+id/ctl_searchText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
EditText ctl_searchText = FindViewById<EditText>(Resource.Id.ctl_searchText);
ctl_searchText.KeyPress += (object sender, View.KeyEventArgs e) =>
{
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
{
Toast.MakeText (this, ctl_searchText.Text, ToastLength.Short).Show ();
e.Handled = true;
}
};
With this code I cannot enter numbers into the text field, but I can enter letters. When I remove the event handler it works again, allowing me to enter all characters. I'm going to carry on investigating, this is very strange.
Please cheack that you doesn't use OnKeyListener. If yes just check that onKey (View v, int keyCode, KeyEvent event) method return True if the listener has consumed the event, false otherwise. In your case it something like this:
ctl_searchText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_ENTER){
//do smth
return true;
}
return fasle;
}
});
Try adding an else stating that e.Handled = false;
Your code will then look like:
ctl_searchText.KeyPress += (object sender, View.KeyEventArgs e) =>
{
if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
{
Toast.MakeText (this, ctl_searchText.Text, ToastLength.Short).Show ();
e.Handled = true;
}
else
{
e.Handled = false;
}
};

EditText Minimum Length & Launch New Activity

I have a couple of queries regarding the EditText function in Android.
First of all, is it possible to set a minimum number of characters in the EditText field? I'm aware that there is an
android:maxLength="*"
however for some reason you can't have
android:minLength="*"
Also, I was wondering if it is possible to launch a new activity after pressing the enter key on the keyboard that pops us when inputing data into the EditText field? And if so, could someone show me how?
Thanks for any help you could offer regarding either question :)
To respond to an enter key in your edit field and notify the user if they haven't entered enough text:
EditText myEdit = (EditText) findViewById(R.id.myedittext);
myEdit.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
if (myEdit.getText().length() < minLength) {
Toast.makeText(CurrentActivity.this, "Not enough characters", Toast.LENGTH_SHORT);
} else {
startActivity(new Intent(CurrentActivity.this, ActivityToLaunch.class);
}
return true;
}
return false;
}
});
There's no simple way to force a minimum length as the field is edited. You'd check the length on every character entered and then throw out keystrokes when the user attempt to delete past the minimum. It's pretty messy which is why there's no built-in way to do it.

Android: Remove Enter Key from softkeyboard

In my login form when user clicks on an EditText and presses the enter key, this inserts a new line, therefore increasing the EditText's size. Next moment, it returns to its previous place and prints a dot in the password field (which is the next field).
I want to remove this enter key from the softkeyboard. Is it possible?
Use :
android:singleLine = "true"
or
edittext.setSingleLine();
And your ENTER key is gone
add this tag to textView in xml
android:singleLine = "true"
I am afraid you can't do this. But one thing is you can handle the softkeyboard keyevents like this,
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Log.i("event", "captured");
return false;
}
else if(event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_BACK){
Log.i("Back event Trigered","Back event");
}
}
}
return false;
}
});
Apart from this, you have to note that providing the attribute android:singleLine=true will make your edittext from growing in size when the soft keyborad ENTER is pressed
Inside the tag EditText you only have to do:
android:singleLine="true"
this remove the enter key in the keyboard
UPDATE
Inasmuch as android:singleLine="true" is deprecated I use android:maxLines="1" to avoid the enter in a EditText. How the name of the method says only N lines is permitted.
New update :
android:maxLines="1"
If you want something more generic in your .java:
boolean state = true;
yourTextInputEditText.setSingleLine(state);

OnKeyListner is not working

Hi Any reply is precious for me and appriciated as well
in one edit text i am setting onKeyListener so that when I enter 5 numerics in edittext it will accept n do next process but in samsung galaxy tablet it is not working i am using these lines of code
zipcode.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
System.out.println("setOnKeyListenersetOnKeyListenersetOnKeyListenersetOnKeyListenersetOnKeyListenersetOnKeyListenersetOnKeyListener");
if (event.getAction() == KeyEvent.ACTION_UP && zipcode.getText().length() == 5) {
System.out.println("OnKeyListener11111");
started = true;
searchByZipcode(zipcode.getText().toString());
}
return false;
}
});
searchByZipcode(zipcode.getText().toString());
line takes the text we are writing in to webservice but in galaxy flow doesnt get into onKeylistner can any1 pls help me out thanks
That's odd. Only in Samsung Galaxys? Is this the full Listener? Maybe you have some other method catching KeyEvents that return true?
Try replacing the code for onKey() by onKeyUp(), which is a TextView method:
http://developer.android.com/reference/android/widget/TextView.html#onKeyUp%28int,%20android.view.KeyEvent%29
BTW, why do you add return false;? Is there any other Listener that requires to handle the KeyEvent? If not, I would suggest to change it for return true;
If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

Categories

Resources