I'm working on an application where need to complete date automatic/suggest while writing. Thing is user can type other text as well so how to sure when he start writing for date.
For reference: I have found similar feature on slack app.
Any suggestion?
Add TextWatcher to the EditText view. In one of it's methods for example beforeTextChanged or onTextChanged get the last entered word (or char sequence - it's up to you to decide which part of entered text you want to check). Apply regular expression to it to check if it looks like date or not. Again it's up to you to decide what looks like date and what is not. If it looks like date - provide users with UI for auto completion or autocomplete by our own. Don't forget to move cursor to the end of autocompleted text using EditText.setSelection() method.
Related
Any one have idea of getting language of user, who is typing in the EditText.
What I Have Tried ?
Please do not suggest Google's com.google.mlkit , I have already tried but not working when user types fast.
I have also tried setting up android:digits="All Alfabets", It is not working when I long press and paste from the ClipBoard, It is allowing text from the other language.
This seems like a very complex problem! And one that limiting the allowed characters won't solve - many non-English languages use the same Latin character set as English, or use it for a romanised version of their written language. nihongo o kaite imasu is Japanese, but that would pass an alphabet check!
Even where other characters are used (e.g. accented versions) it's not unusual for people to just drop them and use the "standard English" characters when typing, especially if they're being informal - e.g. Spanish uses accents on question words like ¿qué?, but people might just not bother (and skip the ¿ too, or just say k if they're being really informal)
And then there's the fact that English does use accented characters - someone can be naïve or blasé, but you don't want your app to tell people they're "not typing in English" if they write those things.
I don't know anything about mlkit but if it's capable of detecting language to some decent degree, it really might be the way to go for such a complex human problem. I'd suggest that instead of trying to interfere with the user's typing, you just trigger a check when they're done which validates what they've entered. If it looks ok, you can enable a button or whatever - if not, show an error message and make them fix it themselves.
You could do that kind of thing with a TextWatcher (or the doAfterTextChanged extension function that comes with the ktx-core AndroidX library) - you'd probably want to start a delayed task so it happens a moment after they stop typing, and that you can interrupt if they start typing again
val languageCheck = Runnable {
// do your check here, enable buttons / show errors as a result
}
// set up the checker
textView.doAfterTextChanged {
// cancel an existing delayed task
textView.removeCallbacks(languageCheck)
// schedule a new one
textView.postDelayed(languageCheck, delayMillis)
}
I'd like to create an EditText that allows user to quickly put in a specific date in format dd/mm/yy, where he only needs to pass day, month and year numbers, without worrying about slashes and overall formating. Is it possible to do that with one EditText or is my only option to create multiple EditTexts and jump the cursor between them?
You could add the date mask "##/##/##" in your EditText. Here is a tutorial on how to do this:
https://medium.com/#diegoy_kuri/masks-in-android-edit-text-fields-33a2fd47f1af
You could solve these by :
Add addTextChangedListener to your editText
Inside afterTextChanged function, add logic to append '/' after user put day and month
By this way, you will get same result for date that displayed to user and date that your code record.
I cannot believe that I'm not seeing more discussions about this issue. Am I missing something that obvious?
I have my activity with SearchView widget with Voice enabled. This a singleTop instance, so that same activity will be able to catch the search intent.
When user inputs using voice, I would like to display the query text to the user for any correction (if needed) before the actual search happens.
In my onNewIntent() method, I handle the search intent to retrive the query text from the voice and update the search text box.
However, as soon as I set the text box with the query text, a new search intent is triggered with the SearchViews Text. And the same is received by my onNewIntent().
This is going in an infinite loop.
I tried to set up the SearchView's OnQueryTextListener, hoping the listener will catch the search text from the text box directly. It did, however, that didn't stop new search intents to be triggered.
I'm about to give up the SearchView. Considering I wanted to have the voice and suggestion features, I'm hoping someone can suggest me a solution for this problem.
Fixed.
The problem was the call to display the query text to the text box, searchView.setQuery(query, false) takes two parameters, and the second parameter indicates if the text needs to be submitted after placing in the box. I must have copied the code from an example and didn't pay attention to second parameter. It was 'true' but should be 'false' in this case.
I have currently a Preference in my application where the user is prompted to enter between 2 and 10 numerical values.
As this feature is only available for power users and beta testers, not for public release, I decided to let them enter a CSV value.
So, in my EditTextPreference, some users will enter: "1;20;30", some other will enter "1;10;10;10;10;10;10;10" etc...
After, in my code, I am just splitting these values to build an array and execute my code.
I have to admit that's not very professional, but that just works!
String[] patternString = PreferenceManager.getDefaultSharedPreferences(getBaseContext()).getString("vibPattern", "0;500;500;500;500;500;500;500").split(";");
The main issue is that I would like to check the validity of the String while the user is writing it!
Does some of you have an idea how to achieve that?
you need to use "addTextChangedListener" and act according to the text that was , well, changed...
if you wish, you can use regular expressions in order to check for validity .
why not just programmatically add the amount of wished boxes, (for an example) have a spinner(drop down menu), from where you can choose the amount, and then add that amount of edittext with numerical only?
In the EditText entry in your layout add the following:
android:inputType="number"
android:digits="0123456789,"
Then on the addTextChangeListener implementations you only have to check if a user just entered a bunch of commas.
I want to make a smart keyboard that can learn and save new words from user. I already made note and keyboard separately, the problem is :
how to read all keystrokes and write it to my note in background?
how to save my note automatically?
thanks for your help
Keep a String or StringBuilder that stores all the text that the user types. All text sent through your soft keyboard will have to pass through the onKey method.
So, I'd do something like this:
1) In onKey, check to make sure primaryCode (the keycode that was pressed) is a letter/number/apostrophe using the corresponding functions. So, something like
Character.isDefined(primaryCode)
2) Concatenate primaryCode onto the end of your StringBuilder/String.
You'll also have to deal with the user moving the cursor/backspacing. In my keyboard, I only store the most recent two words (resetting this whenever the user moves the cursor). That way, the keyboard can learn what the most likely word is given the last word.
You can save your "note" using an ObjectOutputStream or (if it's fairly small) using sharedPreferences.
Send me an email if you run into an more issues: I've been writing a soft keyboard for a while so I'm pretty familiar with it.