Android Layout, displaying Multiple Columns - android

I want to display text such that it would be like:
TITLE 1.1
text about title 1.1
TITLE 1.2
text about title 1.2
TITLE 2.1
text about title 2.1
and so on
it would be a scrolling windows, but another problem is text could be lengthy and could span multiple lines. What do you recommend i should breakup my layout with. The length will be more then the screen height so I need scrollbars. Plus need to keep title bold.
Basically I would be printing this text from a String Array. Is it possible to display it directly from arrays or i can also work with simple strings but need to know how should i breakup my layout. like scrollview -> table layout or what?

Yes it is possible to use String Array. I'd recommed to look at ListActivity and ArrayAdapter. Here is the info to start from.

Related

Set Text Customization in TextView

I have a text that is sometimes too high and at times one word.
How to put the text in this TextView so that the first two lines are located around the specified spacing?
Should this be done by 2 TextView?
If yes, how can I figure out how much text is placed on the top two lines?
You can use a Spannable to add customizations to a string inside a TextView.
The styling android blog has an excellent post about it: https://blog.stylingandroid.com/introduction-to-spans/
But looking to your print, it seems that the first row will always have a style and the rest another. With this, using two TextViews and customizing the view directly is a better option for code and performance.

Android display unicode characters in TextView

I am displaying data in a TextView that is being retrieved from a remote source. Sometimes that text contains characters that don't display properly in my TextView. For example, & shows as &
I tried:
text = Html.fromHtml(text).toString();
Then the characters display properly, but all of the text appears on one line, even if it doesn't fit on one line. From there I tried setting textView.setSingleLine(false); but it still shows as one line of text.
How can I get this text to show the characters properly and also show as multiple lines when necessary? Other solutions suggest manually putting the characters in a string variable, or displaying the characters programmatically, but since it's text that is pulled from the web that isn't possible.
Split your data into separate lines, call fromHtml on each and then join them back together.

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.

How to set text position in TextView via HTML?

I have a TextView in my application and a user can set any text in this TextView using HTML from the application settings. The user must be able to set the position of the parts of the text in this TextView using HTML tags. But TextView doesn't support 'table' tag or CSS. And I don't know how else to set the position. Is there some tag to set the position? Or maybe it is possible with HTML.TagHandler? If it is possible - how?
Two examples:
I want to set align="center" for one line in this TextView with HTML.
I want to separate text to two or three columns.
How can I do that?
I think what you are describing is a WYSIWYG editor like TinyMCE or CKEditor. These would allow you to align text or use tables to separate text into multiple columns.
to set align, line must have its id or class, without it maybe you can use jquery to find needed line ant align text in it.
Maybe text is splited into paragraphs, than you can find needed paragraph with jquery.
To split text to columns is not so easy, try this: How to divide text into columns, if I get text dynamically for database using Javascript and CSS?
You can try <div align="center">Your line here</div>.
Check out this article to see all the supported HTML tags

How to "truncate" a text inside textview in android according to the orientation?

I created a simple java function to truncate a string to be displayed in my list view. I am displaying a news title and below this a news summary. I would like to have the same behavior as the image below. Currently, i am truncating the news title with 45 chars and then appending "..." at the end of it. However, when I change the orientation to landscape, the title could appear without being truncated. I dont think the app below truncates the news title, but it keeps the title in a single line and automatically "truncates".
How can I achieve this behavior in my app?
I don't think you need to truncate title manually. Android TextView component has ellipsize attribute that will do that for you. That also should adopt to any screen orientation.

Categories

Resources