Hey, Is it possible to specify a textview to have 25 characters in a line? I have tried android:maxLength="25" though it shows the first part of the text and the other part disappears.. Thanks
Edit1: I can also put the text into an EditText.. but I want that the characters that are after 25 chars, go to a new line..
http://developer.android.com/reference/android/widget/TextView.html#attr_android:maxLength
I am afraid, maxLength works for input EditText only. :-(
yes , sure android:maxLength="5" works for TextView to set the maximum number of characters for TextView. You can set android:layout_width="130dip" for the TextView too. That will show the character in the format abc... if the text exceed the layout width.
Related
There's a way to set height of an EditText for contains at least n character ?
There are some number of ways that you can limit the editText as number of characters within multiple line as well.
Firstly, set this in your .xml:
android:inputType="textMultiline"
android:maxLength="n"
Secondly, you can also use a way around to reach your goal. Here it is. Implement TextWatcher to let user enter just 'n' characters. Whenever user enters 'n' characters, set the EditText to non-editable. And also set OnFocusChangeListener to it.
EditText editText = (EditText)findViewById(R.id.entry);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
For more details and also explanation of textWatcher, you can have a look number of input characters.
For more manipulation on multiple lines. You can set the number of lines this way, after you have set textMultiline, you can use any or some of below:
android:lines="8"
android:minLines="6"
android:maxLines="10"
android:scrollbars="vertical/horizontal"
Use android:layout_height="wrap_content" in your EditText.
If you want a single row of text only, use android:singleLine="true"
If you want it to have a minimum height set, use android:minHeight="x dp"
If you want it to be exactly n lines tall, use android:lines
For some unknown reason, if I put the following string:
15 קמ
in a text view, it results in a new line between the "15" and the "קמ":
15
קמ
If I replace the "קמ" with "km" then it works fine...
Note: this doesn't happen if both string's parts are Hebrew.
Any clues?
I think that hebrew is interpreted RTL (right to left) while the other part is LTR (left to right). Given this, the TextView has to represent something like this:
\LTR 15 \RTL קמ
My logical guess is that the TextView puts the RTL part on a new line to deal with the nonsense of having both parts on the same line. If you force it all the way RTL when the locale is hebrew, I think it would regulate the rendering and solve the issue. I would suggest you try adding the "RIGHT-TO-LEFT MARK" character \u200F at the beginning of the string:
String text="15 קמ";
if (hebrew) {
text="\u200F"+text;
}
Also, it seems that some fonts are showing a graphical interpretation of the special character (while it shouldn't). You will probably need to use this font to get rid of it.
I have also experienced TextView alignment issue when I'm working with alphanumeric + arabic text in same text view, they will realign all the texts in left to right order which results ridiculous output. This kind of language issue is not really something we can fix in direct approach.
What we did were separating out the texts to more text views if applicable, which in your case I would suggest separating out the value and Hebrew text into separate TextView.
Try to use UTF-8 encoding for hebrew text, for eg:
String text = "15 קמ";
text = new String(text.getBytes(), "UTF-8");
If your textview can fit in one line, I think I might have a solution. This is the xml layout that did the trick.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="15 קמ"
android:maxLines="1"
android:padding="8dp"
android:singleLine="true" />
hi all i have a lil problem in android edit text
actually i made an app in which i m using two text fields for user name and password and set EditText size manually like in 200dip format. now when there is no text in the Edit Text it is in perfect size like in the image below but when we start typing text and the text exceeds the size of editText Field then it Expand downwards like in second image below.
What I want is that when text exceeds the size of EditText, it should not Change its size. please help
android:singleLine="true" should work.
add this property for EditText and check...
android:singleLine="true"
You have to do your ExitText to be single line. You can use android:singleLine but it is deprecated and it's replaced by android:inputType. Use android:inputType=text for single line and android:inputType=textMultiline for multiline
android:maxLines="1"
Another property...
I have a TextView and my need is to add 10 characters in that TextView by code. But when characters are greater than 10, they should be display in TextView but with 8 character + .. of that charsequence. And when I want to read text of that TextView I must get full charsequence not 8 character + .. . For example
tv.settext("ASDFGHJKLQ") // this is 10 characters long, so no rule required
but
tv.settext("ASDFGHJKLOP") // this is more than 10 characters then it should be display as
ASDFGHJK.. in textView, but when I retrieve the value of textview, it should return ASDFGHJKLOP instead of ASDFGHJK.. , so how can it be done.
That textView is row of a listview.
Try adding this to your TextView (marquee or end):
android:ellipsize="marquee"
You may also need:
android:scrollHorizontally="true"
Without scrollHorizontally="true" you may still get the text wrapped rather than appended with ... I use these very 2 lines to display a list view in my app. The 3 long lines I have get appended correctly.
This truncating happens because it does not fit in your list item. Reduce the font ?
or ellipsize ?
I see only one solution. But maybe there are another solutions.
To store you string.
If string's length is greater than 10 letters set text of your TextView with 12345678..
And if you want to get right text you should take the value of the string and not of the textview.
in my custom listview that Contain an image and EditText ,and in EditText i can comment the photo ,i can give text comment max length of 50 ,when i lost the focus in EditText i want to rearrange the text in EditText in following format
EG: suppose comment contain 40 char and user can at a time directly view only 20 char,then if i lost the focus text should be rearranged that at the end there should be 3 dot
Original Comment i wirte:eg-> eeeeeeeeeeeeeeeeeeeeeeeeeee after i lost focus it should shown as-> eeeeeeeee...
it's importent that the nothing happens to original text because these text i want to send to server, and i directly take these values,and if am replace the text by new this type of text this will create problem, also when i gain focus i need to see full text also.
i have used this android:ellipsize="end"
You have to set a specific value for android:ems on your EditText if you want to use the ellipsize function as it will only truncate strings longer than the EditTexts width. With ems or maxEms you can specify how many ems wide your EditText should be. Also don't forget to set android:singleLine to true.