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.
Related
I have a dynamic arraylist that contains String values. I want to match one of its values with AutocompleteText whatever the user has typed/entered. In case the value is not matching with any of the Arraylist values I would like to clear Autocomplete Text.
Couple of Ways I have tried.
Match the typed or user selected value from autocomplete text with list directly without any loop using "contains" method. Didn't achieve the expected result.
Store the values in String[] array from list and loop through it and match it with user input/selection from Autocompletetext. Didn't achieve the result this way too.
Please provide any ideas on how to clear text from autocompletetextview if value is not found?
You did not specify any language that's why i will answer in kotlin
Override onKeyDown method and let's say you will check when enter pressed check if given keycode value equals to KeyEvent.KEYCODE_ENTER
In if block get your text and use an algorithm like below
val arr = intArrayOf(1,2,3) if (textFromTextView !in arr) it means your typed text not in your array and if this condition is true
use autoCompleteTextView.replaceText("") and i hope it will work for you.I never tried but i searched for you.
It selects and copies the number which I am sending and sometimes enters it before the +91 which eventually results in an error.
Below is the code I am using to send a number in to the number input field.
WebElement number = driver.findElement(By.id("com.ulink.agrostar.debug:id/edt_enter_mobileNumber"));
number.sendKeys("7976358798");
You have to first check whether your edit field consist of predefined field like
"+91", If it is there you can override text like these.
if(element.getText().trim().equals("+91")) {
number.clear();
}
number.sendKeys("+91" + "7976358798");
It should work please check.
Is there any good simple way to format fields as I want.
I'd like to separate field value from field text. For example, I'd like to group number by 4, so when I set field's value to 123456789 it would show as 1 2345 6789, but when I get value I'll get number without spaces (123456789).
I think, this is the way widgets works on other tools, i.e. .Net VS. I can set there some mapping, formats and so on, so what is shown depends on value and format/mapping.
In android this must be done for passwords fields. It has text as value, but it shows some dots (value is mypassword and field shows **********).
I guess you just want to display the number in nice format, please use the APIs provided by PhoneNumberUtils.
static String formatNumber(String source)
static void formatNumber(Editable text, int defaultFormattingType)
You could set the formatted string to the text view for displaying nicely. But the saved content is still the raw content without any format.
Please refer to the SDK document at http://developer.android.com/reference/android/telephony/PhoneNumberUtils.html
In my application ,am restricting the user to enter 7.2 digits(like 1234567.12).While entering it should be displayed as 1,234,567.12.But it has to be saved in database as 1234567.12.I am using decimal format as"###,###.##" to display in edit text box.But it is getting error on parsing with float ,while am saving in database.Please tell me any suggestions.
On Formatting ,am using this formatter _decimalFormat =new DecimalFormat("###,###,###.##");
_decimalFormat.setMinimumFractionDigits(2);
_decimalFormat.setMaximumFractionDigits(2);
in ontextChanged listener,On saving in database i am getting error in this line [amountText2.setText(Float.parseFloat(amountText1.getText().toString()));]
Remove the commas in your EditText's contained string and parse that into a float. From your code above, it should be something like:
amountText1.getText().toString().replace(",", "")
Here, you're replacing the commas with an empty string which is pretty much the same as removing them.
I want the user to input the value 4 and have a TextView called result display that it's correct
you are compare String and Editable
try "4".equals(ans.getText().toString())