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.
Related
I downloaded a code and the source is written in this format:
<android.support.design.widget.TextInputEditText/>
instead of:
<EditText/>
I tested both of them and i didn't see the difference, so I want to know if there's a difference between these two ways of declaring a widget in Android.
<android.support.design.widget.TextInputEditText/>
Creates a Field with an EditText with more functions like show the placeholder up the edit text when you're typing in.
https://gyazo.com/844d6c0fe8aace1ef671859823d39a58
https://gyazo.com/bf891de7807955e76bf487e3a07a6317
Only difference is: in landscape mode you can see the hint in TextInputEditText1, whereas you can't see in EditText.
i want to set my textview's inputtypeto be asterisk or in bullet shape. i can set this property using XML file(layout). but when i want to set this programatically it does not work. I use textview1.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); but it show the string that i passed to it. Thanks.
Looking in the original documentation. You need two values since it manage bit definitions:
http://developer.android.com/intl/es/reference/android/text/InputType.html
textview1.setInputType(InputType.TYPE_CLASS_TEXT | InputType. TYPE_TEXT_VARIATION_PASSWORD);
In my project I need to display the instructions page. The page consists of 8 instructions. So do we need to create 8 textviews to display those instructions? Is it possible to display all those instructions using one single textview?
I read about multi-line textviews.
But for my case can I do so to display all 8 instructions in one textview?
As far as I recall, the newline character \n is recognised when used in strings.xml, so you could declare your instructions there and reference it in the layout. I never found a way to do it within the layout XML itself, but there may be something.
Edit: for clarity - I mean using the escaped character, e.g.:
<string name="instructions">Line 1\nLine 2</string>
You can use \n new line character from string resource or thru code:textView.setText("1st line\n 2nd line");
You can use html to format your string: textView.setText(Html.fromHtml("item 1<br>item 2<br>"));
You can use: StringBuilder to it.
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
I would like to create an android widget with a scrollable textview.
The solutions given to this question
Making TextView scrollable on Android
cannot be applied because it is a widget:
1.
This
findViewById(R.id.textview).setMovementMethod(new MovementMethod());
does not work, since findViewById is not available in AppWidgetProvider but only in Activity.
2.Putting a ScrollView around the TextView also does not work, because I get an
InflateException:
android.view.InflateException: Binary XML file line #23: Error inflating class ScrollView
Can anybody give me a hint, how to make a TextView in a Widget scrollable?
I solved this problem by putting the text view inside ListView with single node, which is supported in App widget.
http://developer.android.com/guide/topics/appwidgets/index.html#collections
It looks like this is not possible.
More on this can be found here: http://code.google.com/p/android/issues/detail?id=9580
and here:
How to make a scrollable app widget?
So, probably it is possible to do make appwidgets scrollable in the HTC sense environment but not for normal android environments.
A way around this is to add buttons that go up and down in a list.
I have been working on this with two buttons which increment and decrement through an array. Just having trouble accessing the global variables. Did you make any headway on this?
Another solution is:
Add to textview any web link - for example: www.google.com.
Setting text value with HtmlCompat.fromHtml method:
textView.setText(HtmlCompat.fromHtml("some text" + "\nwww.google.com", HtmlCompat.FROM_HTML_MODE_COMPACT));
After that vertical scrollbar is appeared.
But it's not elegant and full solution. It's temporary workaround maybe...
The complete full solutiion is bat-el-g 's answer - with adding ListView.
Current marked solution (which just tell: "it's not possible") - is wrong.
In mainactivity.java:
after code text view:
TextView txt = (TextView) findViewById(R.id.textView id);
Enter this code:
txt.setMovementMethod(new ScrollingMovementMethod());
and you will be ok.