How to find out text length containing emojis with normal text. I want to limit Edittext for maximum 20 characters. But when I add a new stylish emoji, text length reaches it's limit or sometimes it exceeds.
So I want to count 1 for a emoji. Please let me know if you have idea.
The way I would approach this would be to scan the user input using a TextWatcher and compare against a known list of emoji UTF characters counting a matched set as one character. Here's a list to get you started (I don't know how up to date it is though) https://apps.timwhitlock.info/emoji/tables/unicode
Related
I need to show the price in the Android app. Design is such that text size of two digits after the decimal point is smaller than the rest of the text. I know I can achieve this with multiple TextView views but I'm wondering if anyone did it without the use of multiple views and how to do it.
TL;DR Price should be formatted like this: 5,oo USD (oo in this example represents two zeros as in zero cents with text size smaller than the number 5 which represents the number of dollars)
You can use AbsoluteSizeSpan for your TextView
SpannableStringBuilder yourText = new SpannableStringBuilder("5.00 USD");
span.setSpan(new AbsoluteSizeSpan(fontsize, true), start, end,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
yourTextView.setText(span)
You can find more information from developer webpage
You can
Check the font face that it zeros are smaller that the rest of the digit and apply it.
after setting my edittext's inputtype to numberpassword and following this fantastic post EditText view with keyboard number only , I'm finding that the bullets when in password form take up considerably less space than the numbers they transform from and to. I was wondering how to fix this such that the bullets take up the same x-space as the numbers do.
I want to Show numbers that should increase to a particular limit dynamically.
For Example if I get a number 103. Than my textView should show 1 first and than let us say 3 than 6 than similarly increasing to 103 finally. People call it lottery style text display.
Let us say number is in num variable. than numbers should increase from (num-num) to num.
I designed Logics but if number is very large say 1 billion. than increasing/lottery effect takes too much time.
I am looking for an API where I can specify time in which I want the lottery effect to finish and final number that should be there. i guess this clarifies API requirement..
Do we have any API to do it in TextView in android???
You can create simple yet random number logic for it.
Create an array say of size 10 with random numbers eg 1,13,6,8,3,15..
Create random number class that will give you random number between 0 to array length
So you will get any random number within array each time
Create addition variable, which will get incremented with the above number
before showing the number, check if its larger than the original number
if lesser, show the number, if larger, show the original number
You can implement any other logic, but I have sued this logic, so suggested it :)!
I have a "number edittext". I want to limit the entry of the "number edittext" to 10 million. How can I implement this?
you can set limit in Edit Text for this purpose. try following code
android:maxLength="9"
This will allow you to add number upto 999999999 Rs.
Limit text length of EditText in Android
I am not sure what you mean exactly but i am guessing you don't want the text box size to be more than 1 and 7 zeros, i think the above link should help you if that's the case.
I have items with a lot of text, mostly around 8500 to 9500 characters.
I want to display that in a scrollable textview, but when put the text in a TextView, it seems to be truncated to a max of 9000 characters, while a (the original) String object can hold more. Is there a way to extend this number? Absolutely no parameters on restricting the size of the TextView has been set.
Thanks in advance.
Here is a link which basically says:
The answer is "how much memory can you allocate?" Of course the
system needs to allocate resources to measure and typeset and render
all of that text. If it's too long, consider showing the text in
pages or chunks.
So if your string has 50000 characters, show it in 9000 character chunks.
Use this on your EditText or TextView:
android:maxLength="1000000"
Some phones have an hard limit of 9000 chars by default.
For anyone looking at this in 2018, I don't think there's a hard limit. I have a pretty cheap Android phone with 1 GB of RAM and was able to both edit and display over 40,000 characters of text. There is a slight initial pause when pasting into the edit box and when rendering into a text view but otherwise it works just fine.