Show all possible characters of a too long String in TextView - android

I'm now searching on Google for weeks, but couldn't find an answer to my problem.
I want my TextView to truncate its text, if it doesn't fit. The problem is, as many words as possible are fitted into the TextView, but I need as many characters as possible.
I found an answer, considering using ellipsize with TruncateAt.MARQUEE, but in this case I can't use TextView.getLayout().getEllipsisStart()to check if the text was truncated or not.
Why do I need this? Well, I want the user to hand over a String for the TextView to display. If it is too long, every possible character should be displayed, to give the user a visual feedback. Additional, the TextView should change color. I think, TruncateAt.MARQUEE would work, if I had a possibility to check for ellipsation happening.
EDIT
The font is fixed. Goal of this mechanic is to 'force' the user to enter a String which will fit.

Related

Is there any way to check if a word is truncated in a TextView?

I am creating a custom text resizer for my app and I really need any way to figure out whether a word has been truncated like the word example in the image
I have an idea if I can ellipsize words and then use getEllipsisCount(); but I'm not sure whether it will work and being a beginner I can't even get that done. So what should I do?

Show EditText placeholder for certain amount of characters

This is a simple Android question that is hard to explain.
For an EditText field, I need 18 characters.
I limited the lenght of the edittext now with android:maxLength="18"
What I really need to do is show a dot for each character, or something like a placeholder for each character. I know you can use a real placeholder in Android, but it disappears when you start to enter your text.
Do you guys know any library or other solution for this?
UPDATE: I rather not use 18 seperate edittexts. That would be a lot of hassle to use a textwatcher on each EditText etc..
After trying out your suggestions, I found a solution of my own.
I placed two editTexts on top of each other, set the text of the top editText to 18 dots(.) and enabled to false (to get the greyish look).
I left the other editText untouched.
In code I set both the typeFaces to monospace, to each character would have the same size.
The output is an editText with a grey dot for every character, exactly what I wanted.
Thanks for the help guys, I appreciate it!

Pocket-like TextView automatic spacing based on TextView width?

This is quite hard to understand, but I'm trying to find out how to make a TextView adapt to change the text spacing between words on a line which allows the text to reach the very right side of the TextView.
Consider this as an example (this should get my point across):
This one is a line of text which fills the view itself
This is another that does the same thing
How would I go about making my text react like this? An example application which does this is Pocket, so I know it can be done - I just don't know how.
Any help is appreciated!
What you're referring to is called text justification and is something that has been discussed more than once here on SO in the context of Android.
The short answer is that, unfortunately, justification is currently not (natively) supported by the TextView widget. There are however workarounds that involve either:
Manipulating the text in the TextView in such a way that the result is visually close to that of justification. Example.
Using a WebView to render the text. Example.
Justifying text on a web page is trivial, but the WebView is a more heavyweight component than a TextView, and hence the feature will come with a performance penalty.
Note that I don't know what approach Pocket is using for their articles, but there are ways to figure that out, and they're not too complicated. That's a completely different can of worms though, so I'll leave it at that.

android text wrapping

In my android application, I am displaying a long string into multiple pages. I achieve this by breaking the long string into a string array where every array element holds the number of characters which can fit on one screen (without scrolling). Also by using a previous/next button at the bottom of my activity I change the content of my textview to switch between pages(array elements).
Where I am stuck is in finding out how many characters will show on one page/screen. Remember I don’t want user to scroll. I use the paint.breaktext with screenwidth as the parameter and find out how many characters go in one line and then multiply it by number of lines on one screen to get the number of characters in a page. Android’s text wrapping at the end of each line is what gets my calculation of finding characters in a page, wrong. I am trying to put my own logic to accommodate for text wrapping but that is not working.
So my question is:
Is there any way I can find out that how many characters will show in one screen?
Or what can also help me is if I find out what logic is followed by android for wrapping the text for newline. Because if I know that, then I can readjust my number of characters on a page accordingly.
Or other option could be to disable text wrapping (not sure if possible). Because then I can use my own logic to wrap the text rather than trying to figure out Android’s text wrapping logic and adjusting my character-on-a-page accordingly.
Any help is much apreciated.

Android TextView carry text by letters

Is there any way to carry text in TextView by letters in Android?
If no settings have been set – TextView carries text by words and situation is possible when with too long word you have big whitespace in TextView.
Example – what I’m talking about:
If you can get it at the TextView in XML, I would try giving it the attribute:
android:singleLine
If you have to do it in Java, there are a couple of options to keep it on the same line:
textView.setSingleLine();
textView.setTransformationMethod(new SingleLineTransformationMethod());
If you do want multiple lines, but you want it to break in a way that doesn't split it on the word, you might have to do it manually by analyzing the width of the TextView and how many characters can fit on a line, then inserting newlines appropriately. The two above methods will keep the contents of the TextView on one line, and it'll scroll horizontally. You can look into how this person is doing it.
Another option is to look into the android:ellipsize attribute, but I don't think it'll do what you're looking for.
Not sure if I understood correctly what you want, but I would guess.... if you would like to display the TextView in a single line, without "breaking" the sentence, you should add android:singleLine="true" to the TextView.
Otherwise, you may replace the "_" characters with space, in this case I believe it will carry the text, from the last space.

Categories

Resources