I want to access text of particular line in a multi-line TextView. Any suggestions on how I could do this?
Fetch the Layout (android.text.Layout) of the TextView by calling mTextView.getLayout(); There you can for instance use the getLineStart or getLineEnd methods to get the offset of the text. That combined with getText and used using normal String operations should probably be enough for u!
By default, text view is multi line. Set the text with new line characters for ex. "First line \nSecond line".
Another option is listed here : https://stackoverflow.com/questions/2610280/how-to-get-multi-line-text-on-a-button-in-android
Related
My point is i only can write/select 1st line of the textview i want to have for example:
My name is:
12345
Is it even possible to write in 2nd line or more lines?
My name is:\n12345
for more lines use more \n\n\n\n\n :-)
You can also do many thing like....Bold italic or showing in list using one Text view.
Write your text in HTML format. i.e
String youttext="<b>My Name is Avi</b><br><br> <i>I m a Android Developer</i><br><br><ul><li>I m a Blogger too</li></ul>"
Textview yourview=(Textview) findViewById(R.id.textview);
yourview.setText(Html.fromHtml(youttext));
You can show the Text in HTML format too. If you want to change the specific color text and style or shading etc.
I am creating an app in android and I am parsing text. After I parse the text, the text appears fine. However, I don't want all of the text to appear (i.e. all lines to appear together).
Example -
Text that appears in app:
A Turing machine is a device that manipulates symbols on a strip of tape according to a table of rules.
What I want to show:
A Turing machine is a device that manipulates [more...].
So when the user taps on the [more...], the rest of the text will appear in a new window.
How do I incorporate the "[more...]" part?
Thanks =)
declare in your text view properties in the layout file
android:ellipsize="true"
that should do it.
use android:singleLine = "true" and
fix the width of your textview like android:layout_width = "150dp", then append [more...] at the end of text and make it as link, which should be clickable
Refer to this, to do what you want...
I have TextView. Using java code I want to set color for string variable that I have to append to the text. Variable is generated at run time.
I explored Spannable but you have to give start and end which is not fixed.
Any other way to fix this. Please help.
Code:
String text; (Filled at runtime)
//but I want it to be different color
textview.append(text);
You can do something like this to set the text in your TextView:
tv1.setText(Html.fromHtml("<font color='red'>R</font><font color='green'>G</font><font color='blue'>B</font>"));
The issue with this is that when you have just one text object you can only have one colour for it. You will have to use more then one text object (each with different colours) and juxtapose them in you design.
I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,
textView.setText(Html.fromHtml(someText));
Is there a way to do this through the XML?
I ask because i do not want to set the text through the code, In my case, the text comes from a DB call and displayed through an adapter.
Yes there are a bunch of (simple) tags that are understood by TextView -- if the text is set in XML from a string resource.
So basically
<TextView text="#string/foo" .. />
It is also possible to give templates like "Hello <b>%s</b>", but here you still need to run some code to fill in the value for %s
Have a look at http://developer.android.com/guide/topics/resources/string-resource.html for formatting hints and short examples.
i think you may get the idea of wat i'm trying to do if you look at the code:
here the complication is that i cannot create another textview for another line....
s8="hello";
t12=(TextView) findViewById(R.id.solid);
t12.setText("check"+"/n"+s8);
The correct notation for newline is \n not /n. TextViews in Android are multi-line enabled by default, so no other magic should be required.