Editext validation for button click - android

I have an edittext and when the button is clicked it allows only Strings.
I do this by using an if statement to show a dialog with this condition: (str.matches("[0-9]*")
but when I enter this ttttt12323 and press the button it allows string and int to go through.
I want to put validation for not allowing string and text together specifically only Strings.
Can this be done. Thanks

So you want to check if your input consists of characters only, right?
You could try something like (str.matches("[A-Za-z]*")

Related

How to make a text field that can be entered when the user clicks it but otherwise is disabled?

I think I'm missing something very obvious here.
All I want is a field where users can enter a parameter that affects the app, for example -100
I want the field to be visible on the screen, displaying the current value of the parameter, but not with a cursor in it or underlined in red or anything. Simply visible, but if the user wants to change the parameter, they can click in the box and change the value.
Many thanks for your help!
You can try to add both TextView and EditText in your layout, then show and hide based on your need.
Just show EditText by default and add TextWatcher on it, when enter is pressed or saved, then show your TextView with value from EditText. Then write onClickListener for TextView to show EditText again.
Hope that makes sense.

AutoFill EditText Android

I'm trying to create a search bar like.
I have to use a particular autofill, infact I can't use a dropdowns menu.
For example if I write Noce the edittext will have to suggest Nocera in the same editText, like this.
but if the user write something else the pointer have to the end of the typed text (in this case Noce) and the hint have to disappear.
Is there some library that allows me this?
Thanks for the help.
There's this library that will fulfill some of your requirement called Auto Fill EditText
Finally I have solved this using two EditText in the same position. The first one is a normal editable EditText, the second one is not editable from the user but is used to show the hints programmatically.

Android add new form and button dynamically

Currently working on an Android app. I want a page to have a button, and when clicked on, I want it to create a form. When they press the button again, it will create another form, and so on. Just like when you are on a website, and add your emails or anything, and you press "add" button, which will create a new input field each time.
Also, next to the input field has a name (same for each time) like
fieldName: [___input_field____]
fieldName: [___input_field____]
...
(+) //there is a button, and pressing this button will create a new form above.
I am not sure how to go about this. I want each input field to have a different ID, but is it possible? Each input field is going to be filled with a number, and in the end, I want to add all numbers in the form to find the average of them.
it will be easier and cleaner create a child layout with your form and inflate that child every time you need a new form and to get each item you can use View.getChildAt(position);
http://www.android-examples.com/create-edittext-dynamically-using-java-file-in-android/
This link shows a simple way to add an edittext dynamically. For what you have mentioned above, you have to use edittext array and for each "add" click, create edittext like et[i] = new EditText()...
Then on final submit click retrieve edittext datas from this editext array

Android how to get Suggested strings array of the TextEdit

Is there a way to get an array of the suggestions strings which are shown when you typing in EditText? The problem is I have an EditText and in case of user use "Show Suggestions" option the result of the string from this EditText is different in case of user pressed, lets say UI button (this is a Button from the layout), and a return button at the soft keyboard. In first case user gets an exact string but in second - it gets corrected (suggested) string even user do NOT select this suggestion. How to solve this problem? How to get from EditText "suggested" string? Do I need to implement my own IME?
Maybe this can help you ? Hello Auto Complete
Or if you want to write one on your own.. Writing your own autocompleteview
Are you trying to disable suggestions or to modify them?
If you want to disable them completely, check this out:
How to disable displaying "suggestions" on the Soft Keyboard

Type in EditText with buttons

So I hid the soft keyboard because I only want "1" and "0" to be the buttons to type with and a delete button. I have two EditText boxes. How do I go about letting the user click on the EditBox and be able to have those Buttons only type in that box? and same with the delete. I only need to know how to make it recognize that you have chosen that box. Take whats there and add "0" to the end of the string.
Thanks
If all you are looking for is to get the EditText that is selected, then use the hasFocus() method on each EditText. The method returns a Boolean value depending on whether or not it has focus (has been selected by the user). Then insert your text into the EditText that has focus.
If this does not help, I've done something similar to this before and can offer you a different solution.

Categories

Resources