Max 9000 characters in Android TextView? - android

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.

Related

Find out text length containing emojis

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

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.
I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.
Can someone help me about it?
Thanks
I have you considered using a custom font? Some font types are made to stretch out or shrink or have empty spaces. With so many different fonts available online, you can definitely find something. You can also make your own with a software. It might be time consuming if you start the lettering from scratch. I'm not 100% sure if it'll fit exactly to your background, but it's idea that you can consider.
If it doesn't fit, I supposed you can always customized the background to fix your font too. Here's the code for those who might want to use custom fonts in their app too.
Typeface myfont = Typeface.createFromAsset(getAssets(),
"fonts/Blocks2.ttf");
myeditText.setTypeface(myfont);
The font is in the asset folder under another folder called fonts.
This question is related to How to change letter spacing in a Textview?
As shown at this issue: android format edittext to display spaces after every 4 characters a solution might be to insert spaces with Java code...
You need to use TextWatcher to achieve visual purpose spaces.
And use any simply split string by space logic to join it back or loop
through the entire string per character wise and eliminate (char) 32
from the string
As far as i know actual character spacing is not possible, though i'd love to use that myself as well.
Another option might be to use a custom font with the character spacing included.

Android: Way to set physical length of edit text field

Is there a way to limit the input length of a Android edit text field using some sort of physical parameters (i.e. inches, pixels, etc.) I do not want to limit the field by character number.
Thanks for the help!
you can use android:maxWidth="100dp" but that is going to set the max width of the View itself, and will not affect how many characters are allowed to be typed into it.
I do not beleive there is an easy way to accomplish what you want. The only thing I can think of is use a TextWatcher and dynamically determine how many characters will fit in the the size that you are wanting (which will be different for different devices). That is still basically "limiting the field by character number" though which you state you don't want to do.
Can you elaborate on why you are wanting to do this? Perhaps there is a better way to solve the overall challenge that you are facing.
You want to add a text changed listener (TextWatcher). In your listener you'll need to measure the size of the font, and the pixel density of the screen, and the number of characters. Multiply all of those together and you should know how physically long the text is (with a few caveats).
Having said that, this seems like a weird restriction and I'm not sure why you want this. Every device is going to have a different screen size, so measuring your interface in inches is typically a bad idea.
You could find how how many M's will fit in the printed form and then use EditText.SetMaxEms To make sure the input will be printable on the form.
Try this on your EditText
android:maxLength="10"

Display html formatting in listview android

I've got a list view in which i have to dispaly some text from html with proper formatting. Though i pass the html as string to Html.fromHtml method but my formatting as align="justify" don't work.
here is the code snippet:
String text = "<ul><li><p><div align="justify">as part of its growth plan, the ranchi-based central coalfields ltd (ccl) is gearing up to double the company's production in the next couple of years and also to increase the capacity of coal washeries.</div></p></li></ul>";
i pass this this string to
Spanned nText = Html.fromHtml(text);
and then i display it on the screen
When String nText displays on the emulator screen the formatting that should be there, i.e. the text should be displayed as justified, is gone.
Please help
I have found that using Html.fromHtml() can be somewhat hit and miss because some html tags are supported, and others are not. Justified text is not generally supported within Android mainly because, I suspect, that it can look pretty dreadful with relatively short lines of text. It would not surprise me if justified text is not supported in fromHtml().
Personally I would avoid justified text on a small screen anyway because it can be difficult to read.
If you really need justified text, I think that you may need to write something which implements android.text.style.AlignmentSpan and write your own text justification routine, which will not be a trivial task.

Setting the text of a TextView when the desired input is larger than ~4000 in String length()

I am trying to setText(string) on a TextView component and I am not seeing the text I set. The input String is larger than 4000 in length(). I find that if I reduce the text size, the text will display.
How can I setText(string) on a TextView with all of the input String visible without changing the text size of the TextView?
Do I have to split the input String and use multiple TextView objects?
How will I know if the input String will be too large and not be seen, as my TextView may be filled with dynamic text?
Let me guess - you have a Samsung phone? Samsung saw fit to modify the operating system to have an implicit maximum size on all TextViews. Why? No idea. But if you specify the length with android:maxLength, it'll work just fine.
See here: How can I debug a seemingly hardware-dependent issue with my Android app without access to the hardware?
I have the same problem with Sony Ericsson Xperia.
I have solved it by using EditText with inputType="none" and editable="false"
I hope it will help you.

Categories

Resources