Focusing fields in android? - android

i have ten edit text item and validation for each field , when i click submit validation is processed , and if any invalidate field throw an alert , for example i have first name need to contain minimum 6 character , if validation fails i throw an alert .
what i need is to focus the invalidate field automatically after throwing alert for entering the right values.
If there is anyway to do this.
Thanks.

use the requestFocus() method on the edittext containing the invalid value

Related

getting text length limit of current input field - Android Input Method

I am developing a soft keyboard. I want to notify user the maximum text length reached.
Is there any way to get maximum text length allowed by current input field in which user is typing ?
getCurrentInputEditorInfo() returns EditorInfo object which contain many details including fieldName, fieldType, hintText, etc
But there is no field to get text length limit detail.
The application programmer can set field length limit for his EditText using following line.
android:maxLength="15"
I am talking about retrieving this information.
One of the items you can get from the EditorInfo object is fieldId. You can use that with findViewById to get the actual EditText and from that get the length using one of the techniques detailed in How to Get EditText maxLength setting in code.

How do I make a toast display for this specific edit text field

Hi I am kind of stuck here, I have an activity which lets the user create a transaction from his bank account, the activity has some text fields.One of the text field is for balance entry. When the user enters the balance he wants to withdraw there should be an internal checking of the balance present already in the user's account. I know how to create the internal checking, the problem is that when the user enters an amount in that particular text field there should be a toast displayed letting the user know that he has entered an invalid balance withdraw request,or something like that. How can I do this? Are there any listeners for accessing that particular text field?Thanks.
Instead of showing a toast message, you should use TextView.seterror . This can be done where you are doing checking.
I would use a TextWatcher
Just add the Textwatcher as a listener on your editable:
editable.addTextChangedListener(new TextWatcher() {
//Override Methods
});
In the method afterTextChanged(Editable s) you can start your validation. If validation fails you can inform the user with a Toast or an error text(setError) on the Editable
If you want to display a validation error on a specific EditText you should use:
{EditText}.setError(CharSequence error)
OR
{EditText}.setError(CharSequence error, Drawable icon)
That should bring up the toast you want.
Regarding the logic of validation, it's up to you of course...

Default empty spinner

How I can set spinner empty by default? I mean that spinner doesn't have value (empty value) till user choice it.
I usually just provide one fake value with toString empty string. Then the spinner appears empty to the user. Afterwords just perform validation before you finish the activity and if the default value is still on, just show an error, rather than continuing on.

IndexOutOfBoundsException in Edit Text for android

i have an edit text in my activity.i am entering numbers in it manually but
int mystart = destinationNumber.getSelectionStart();
int myend = destinationNumber.getSelectionEnd();
numberText.getText().replace(Math.min(mystart, myend), Math.max(mystart, myend),
"1", 0, 1);
its entering fine according to the cursor position.
i have a delete button in my acitivity which deletes single character according to cursor postion.
numberText.getText().delete(myend - 1, mystart);
But this logic is not working properly when i select whole text and call delete method it gives me IndexOutOfBoundsException OR i select 4-5 digits and call this delete.
I want the same functionality as android contact dialpad number enter field.Can someone help me figure out what is the correct logic to delete single digit from edittext and multiple selected digits as well.
Thanks
delete receives the start as first parameter and end as second, not the other way around.
Probably the error its taht mystart or myend(probably this) are bigger or smoller than numberText.lenght().
Try to put a Log.d("","" ) with the lenght of the text, mystart and myend and check if you need a myend -1 or something like that.

Find out the new element in EditText View

I want to execute one method wheneer i enter number in EditText view.But i did not change the focus of EditText.I am stay in the same EditText when i enter a new number automatically i eant to execute one function.Now my question is how we find that event that means enter a new number in EditText
You need to associate a TextWatcher to your EditText, and then, check in onTextChanged() if the character added was a number. You could use a regular expression for that :
if(s.matches("[0-9]")){
doYourStuffMethod();
}
You can also use the Matcher class from Android SDK which is an helper for this kind of stuff.

Categories

Resources