Masking Input in EditText in Android - android

How to use inputfilter for CNIC i.e #####-#######-# ? Please help me.. I am new to Android and I dont know how to use it?
How to mask input? I went through various sites but couldn't find solution. I am so confused.

Have you tried using Masked EditText ? This is what you want ... :)
If you want a numeric keyboard instead of alphabetical, then comment the following lineof code:
this.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
in the file MaskedEditText.java. Now setting android:inputType = "numeric" will work.

) You can also try the fork of Masked EditText. It's derived but with works with Gradle, has some bugfixes, an example project, and a little bit another behavior :-)
The behavior is also changed:
You can set the flag and the hint will be always visible.
Your pattern is invisible initially and grows automatically as soon, as you type. For instance, in the beginning, it is: "+7(", then you type '999' and it shows you "+7(999)" with another brace. In the original library, AFAIK it works like: "+7( ) - - ", then you type '999' and it transforms into "+7(999) - - " and so on.

Related

Why does setInputType disable autocorrection?

Normally the android keyboard automatically shows suggestions as you type (autocorrect), but if you change the properties of the edit field from your code, the suggestions no longer show up.
For instance, this line successfully changes the input type to use all caps, but suggestions no longer show up:
mEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
Even if I explicitly tell it to use autocorrect, it STILL doesn't use autocorrect:
mEditText.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
However, if I never call setInputType, the suggestions show up just fine! Why does this happen? How do I fix it it?
Thanks!
I don't remember the full story, but I had to do the following to make it work for me
edit.setRawInputType(edit.getInputType() & ~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE);
note the calling of setRawInputType instead of setInputType

TextField ellipsis nativescript

I'm developing a Nativescript app, and in some devices the hint is bigger than the input, IOS add three dots at the end (...) like an ellipsis, but android only cut off the hint.
I tried the following code:
let shareInput: TextField = this.page.getViewById<TextField>('share-input');
shareInput.android.setEllipsize("end");
I'm getting an error like this:
java.lang.Exception: Failed resolving method setEllipsize on class
android.widget.EditText
I red some android issues and tried to use setSingleLine method but it does not work.
Any help is welcomed.
So this method is what you need (and are using :) - https://developer.android.com/reference/android/widget/EditText.html#setEllipsize(android.text.TextUtils.TruncateAt)
your argument is incorrect, it isn't expecting a string but an ENUM.
So try setEllipsize(android.text.TextUtils.TruncateAt.END)
And if you're going to be setting this on multiple fields I would add a var for the TruncateAt enum like const TruncateAt = android.test.TextUtils.TruncaeAT then just use that const/var in the argument like (TruncateAt.END) to save on repeating yourself.

How to include suggestions in Android Keyboard

I am working on Android SoftKeyboard. I've created layout for keyboard but dont't know how to include suggestions which appears if we type some word in EditText.
For example if i write "Kn" then "Known" and "Known" are shown in Suggestions.
So my questions are -
1) How to include suggestions in Android Softkeyboard?
2) Is there any way to include our own list of suggestions?
Thanx a lot in advance.
I've already checked this and this but not able to find any proper answer. Any help would be appreciated.
EDIT
I want to include suggestions directly above Keyboard as shown in picture below.
You can use the static method UserDictionary.Words.addWord(....): Link
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// On JellyBean & above, you can provide a shortcut and an explicit Locale
UserDictionary.Words.addWord(this, "MadeUpWord", 10, "Mad", Locale.getDefault());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE) {
UserDictionary.Words.addWord(this, "MadeUpWord", 10, UserDictionary.Words.LOCALE_TYPE_CURRENT);
}
You will need to add this permission to your manifest:
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/>
Added words will appear in Settings > Language & input > Personal dictionary.
If you are implementing your own soft keyboard, I suggest you go through Creating an Input Method. The suggestions are usually shown in the Candidates View. By default, InputMethodService#onCreateCandidatesView() returns null. You should override this method to return your implementation of the suggestions bar.
Here's a sample project that implements the Candidates view: SoftKeyboard.
More info:
Word and phrase suggestions go in the candidates view. Info about how to create & populate it are in the sample project mentioned above.
As far as I know, the selection of what words/phrases to suggest is developer's responsibility. Android does not provide those for you. You will probably need a set of dictionaries - one for each language/locale you plan on supporting. You may also want to maintain a dictionary of user-specified words.
Android's default keyboard uses these: Link
If you download one of these, unpack it and open with a text editor:
dictionary=main:en,locale=en,description=English,date=1402373178,version=47
word=the,f=222,flags=,originalFreq=222
word=to,f=215,flags=,originalFreq=208
word=of,f=214,flags=,originalFreq=214
word=and,f=212,flags=,originalFreq=212
word=in,f=210,flags=,originalFreq=210
.... 165,635 more lines
As apparent, the frequency plays a pivotal role in determining the suitability of a word as a suggestion. You probably don't want to suggest tachometer when the user types ta. You probably do want to suggest take - frequency helps you there.
Autocorrection:
word=id,f=99,flags=,originalFreq=99
shortcut=I'd,f=whitelist
The flags indicate appropriateness:
word=goddamn,f=0,flags=offensive,originalFreq=62
Even if you decide to use these dictionaries, the code to parse them and obtain meaningful suggestions will have to come from you.
Two articles (both by Peter Kankowski) that talk about predictive text input & spelling correction:
Using DAWG for predictive text input
Using Ternary DAGs for Spelling Correction
CandidatesView:
The first thing you should know about the CandidatesView: it is optional. In fact, LatinIME (android's default soft keyboard) does not use it. Instead LatinIME has its own implementation - SuggestionStripView - which is similar. The default behavior of InputMethodService#onCreateCandidatesView() is to return null. If you choose to provide your own implementation, don't override this method.
You need to decide what your CandidatesView should look like. One possible implementation can be a HorizontalScrollView. After you evaluate your suggestions (for example, user start writing "as", and your suggestion-logic gives you a List<String> containing "has", "was", "assist", "ask", "asked", "asking", "assume"), create & add TextViews holding these strings to the HorizontalScrollView(LinearLayout). This way, user can scroll horizontally and choose the intended word by clicking on it.
It is up to you to decide whether to use the API or handle the CandidatesView yourself. If you want to use the API, override InputMetodService#onCreateCandidatesView(), inflate your custom layout, then return it. Hold a reference to it, so you can update it when required. To control CandidatesView's visibility, use the method setCandidatesViewShown(boolean).
If you are creating a custom keyboard, I suggest you go through Creating Input Method, there is a sample code that you can go over. CandidateView is probably what you are looking for. It is explained in the link above.
If you want to provide inline spell checker, you would want to check out Spellchecker framework
Hope this helps.

MonkeyTalk Android Detect String Containing \n for Button Tap

I am using MonkeyTalk to automate some user test cases for my Android app. Everything is working fine except for when I try and detect a button containing this string:
"Connect\n(Code Required)"
I get this error:
FAILURE: Unable to find Button(Connect\n(Code required))
If I change the button to "Connect" and perform a tap on that value MonkeyTalk has no trouble, but something about the line break must be throwing it off.
After some searching I found this thread that confirmed my suspicious about the line break. There was one suggested fix here, to set the default encoding to UTF-8 (Select the Project > File > Properties > Resources)
However this did not work for me.
I have also tried to find the button using a wildcard like so:
"*(Code Required)"
But this does not seem to be supported either.
Maybe there is an alternative line break character I could use?
Thanks in advance for the help!
Maybe there's a carriage return in there? I know in most text editors a new line actually consists of (carriage return)+(newline).
Also take a look at this:
TextView carriage return not working
Also, depending on how flexible your requirements are, you could use the #N MonkeyId replacement to get the Nth button.
IN javascript you can use below command
app.button("buttonname").tap(x, y);
Use android:contentDesxription="your_component_id" in your view xml file definition or view.setContentDescription("your_component_id"); directly on view in code to make it easy to access in MonkeyTalk.

How do I set multiple input types in an EditText on Android?

I am trying to create an EditText with auto-capitalization and auto-correction implemented. I have manually figured out how to add InputFilters to allow auto-capitalization, though this only works after the first letter is typed, and I have had no luck with auto correction (I tried to create an InputFilter that used AutoText, but I'm not sure how all that works). Ideally, I could just use EditText.setInputType(...) to handle everything, but so far this has not worked. Is there a way to achieve this? My failed attempt is shown below (I just get normal input).
EditText mEditText = new EditText(this);
int inputType = InputType.TYPE_CLASS_TEXT;
if (auto_capitalize) {
inputType = mEditText.getInputType() | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS;
}
if (auto_correct) {
inputType = mEditText.getInputType() | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;
}
mEditText.setInputType(inputType);
Please note, I am only interested in solutions for creating this EditText in code - not via XML.
Edit
I found sound new documentation describing TextKeyListener, however after trying to use this:
mEditText.setKeyListener(new TextKeyListener(TextKeyListener.Capitalize.CHARACTERS, true));
and using #farble1670's idea of using setRawInputType, so as not to affect the KeyListeners, there is still no change to the text.
Through XML it would be setup like so.
android:inputType="textMultiLine|textNoSuggestions"
You simply add a pipe (|) between variables. I see you were doing it through code but I was just throwing this out there for reference.
I hope you've found an answer to the question. The answer might help those those come to the thread later. So, you can set multiple tags in similar manner as you do in XML using a | (pipe).
Something like:
EditText mEditText = new EditText(this);
mEditText.setInputType(InputTpe.TYPE_TEXT_FLAG_CAP_CHARACTERS|InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
Also, depending on your situation you might want to use setInputTypeor setRawInputype.
Yes, it seems like that should work. However, looking at the docs,
The type of data being placed in a text field, used to help an input
method decide how to let the user enter text. The constants here
correspond to those defined by InputType. Generally you can select a
single value, though some can be combined together as indicated.
Setting this attribute to anything besides none also implies that the
text is editable.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
So it looks like in general, you can't expect to set two values. The above link shows which flags can be combined together.
Also, if you look at android:setInputType, it says this maps to the setRawInputType() method, not setInputType(). You might try calling setRawInputType() in stead of setInputType().
http://developer.android.com/reference/android/widget/TextView.html#setRawInputType(int)

Categories

Resources