Android - Insert large text in an Activity - android

i need to create an activity with the description on an object.
This description is about 1000 characters, on 16 line.
I wanna ask if there is some way or some rule to follow to insert a string big like this in a textview in android?
I only have to format in in the values/string file or i have to do something else?
And in this description there are some link, how can make them clickable? (when i click i wanna open my browser with the link).

To make links clickable just add this to your view :
android:autoLink="web"
Yes you just need to add that text to resources.
Best wishes.

Put the string in strings.xml, set it to a text view inside a scroll view so that it doesn't get hidden on smaller screens, set autoLink to make the links clickable.

Related

Custom rendering for text with special syntax

I have a text gathered from API and it consists of custom syntax. I display it using TextView but I need to render special part of the text and convert those text into elements. An example of a text is below.
Oh, that's great idea! Check (user: someuser)'s answer for this.
You can as well look at (ref: a forum post title) or:
(ref: another forum post)
This is a hint for you! (hint: should be displayed as a mini icon
but when clicked, a tooltip should be opened)
Here is a spoiler for you.
---- spoiler ----
some spoiler. this text should not be displayed directly but it should be
converted to a button element. When the button is clicked, this text should
be shown
---- spoiler ----
So, I need to convert (user: someuser) into a link in the view which will be shown as "someuser" but when clicked, it will open a new intent. For (ref: topic) keyword, it's the same. When I hit spoiler, I want to make it a nice button indicating that it's a spoiler and when user clicks, it will expand.
How can I parse this text and show correctly in a view? I don't have problem with parsing but my problem is displaying those elements in the view.
Methods I Tried
I tried WebView instead of TextView thinking that I can convert those into HTML/Js but the performance was terrible. Although I use RecycleView and ViewHolder, WebView is simply an overkill. I need to use some kind of a TextView but with the elements I would like to have.
I also looked at custom HTML tag handling with TextView (thinking I can convert those legacy tags into html) but I failed to see how I can insert button for spoiler tag or insert custom elements like tooltip for hint.
Thank you!

Android - Questions about Edit Text in WebView

I'm using a Edit Text to put in a URL to search in the Internet. But to use a URL, I need to put http:// in front of the Url. Is there a way, to hide this and use it for default?
And the other thing is to have only one single line in the Edit Text?
Thanks
Is there a way, to hide this and use it for default?
When you retrieve the value from the EditText, see if it begins with a recognized scheme (e.g., https://). If not, add it yourself, through string concatenation or StringBuilder or something.
And the other thing is to have only one single line in the Edit Text?
Use android:maxLines="1" in the <EditText> element in your layout.

URL as a link in listview in android

I am new to android and I am trying to contribute for an android project. There is listview of messages and when a user clicks and a specific message, another view opens and shows the details as shown in below image(android view).
All these information is being fetched from web and parsed. and link is not clickable on web view also as shown in below figure (webview),
It is not shown as hyperlink on webview. I think that is the reason its not showing as a link in android app too.
Can anybody help me with this? The code related to this can be found at : source
related files are:
\scraper\MessagesScraper.java ,
\scraper\SingleMessageScraper.java ,
\ui\messages.java
\ui\SingleMessage.java
Any help would be great. thanks in advance.
In your XMl wherever you define that particular TextView add the following to that TextView
android:linksClickable="true"
Also see How do I make links in a TextView clickable? if you want to for example hide the URL and just show some text for the link.
Edit: From what I can tell...
MessageScraper is using ThreeLineAdapter - https://github.com/pradeepb6/TuCanMobile/blob/master/src/com/dalthed/tucan/adapters/ThreeLinesAdapter.java You can see all the TextViews here and then go to the res folder and change them accordingly.
SingleMessageScraper seems to be just using standard ArrayAdapter and Androids Simple_list_Item_1 for the layout. http://developer.android.com/reference/android/R.layout.html#simple_list_item_1 So if you need to you'll need to make your own list_item layout for this if it doesn't make sense to use one that was already created.
I don't think the UI classes need any changing.
Re: Comment - A single message (shown in your picture) is a listview of TextViews. You could also have a listview of custom views if you want more things in each cell, which is what the ThreeLineAdapter is handling.
If you are using TextView in your ListView's getView function,
you can use Linkify to convert the link to URL
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("http://www.example.com");
Linkify.addLinks(textView, Linkify.WEB_URLS);
WebView.getSettings().setJavaScriptEnabled(true);

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

1 line text view next to two line text view

I was wondering if this can be implemented in android.
So there are basically two text views one is the name / other is the "open" .
The name can extend more than one line and the "open" should be placed adjacently .
One way is to dynamically break the name text view into two and place "open" next to it. But I don't find it good solution . any direct way to implement it ?
You may set the following to your TextView:
android:drawableRight="#drawable/your_image"
You could create ListView and use
setCompoundDrawablesWithIntrinsicBounds in the layout for your Adapter. Create a Boolean to show when a pizza joint is open and when to show the Drawable.
Something like this:
if (isOpen){
yourTextView.setCompoundDrawablesWithIntrinsicBounds(0,0,0, drawable);
}
Of course, this would require you to make an "open" image, but the way I see it, this would be the easiest way.
Just a thought .
It can be done via setting text using textView.setText(Html.fromHtml(styledText));

Categories

Resources