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.
Related
I have a TextView and I set text which I receive from Backend.
the text is either from 1 to 3 words.
Maximum the textview can be 2 lines.
I am using setAutoSizeTextTypeUniformWithConfiguration
and text.breakStrategy = LineBreaker.BREAK_STRATEGY_SIMPLE
And I don't have any success.
wondering is it possible if the text is single word I don't want to split it. I would like to have it in single line with small textSize. if the text is 2 words and long I am fine to show it in 2 lines. The problem is it always breaks the word in 2 lines if it is long while I don't want.
The only solution that comes to my mind is before setting the text to a textview, check whether text has spaces in it.
If it has not that that means it's a single word, so set ptogrammatically maxlines to 1, otherwise set maxlines to 2.
EDIT: I missed text size part. I use this library for autoresizing and it worked so far https://github.com/jivimberg/AutoResizeTextView
it's automatically handled in androidx.appcompat.widget.AppCompatEditText and just set android:maxLines="2"
remove all other properties you set
I have a textView where I am getting data from JSON and displaying. My problme is that I want to store all data into database but want to display few letters on TextView. I used
android:singleLine = "true"
Is there any way to show only few characters in textView but getting full data in background ?
You can use in xml android:maxLength="10"
You can use android:maxLength="10" (for showing only 10 characters). Apart from android:singleLine = "true" if you want to show 3 dots at the end of the text then you can use android:ellipsize="end"
To store the full text data in database , store the json string which comes from server , however in the textview use maxLength property to restrict the number of characters. Hope this helps.
android:maxLength="<Any character Length>" (for showing only n
characters).
android:singleLine = "true"
if you want to show 3 dots at the end of the text then you can use android:ellipsize="end"
So storing the full text data in database , store the json string
which comes from server , however in the textview use maxLength
property to restrict the number of characters.
Hope this will help you !.
android:singleLine = "true" doesn't have to do anything with the data in background. You will get your data in database as it is.
singleLine will only show the maximum data it can show in a single line on UI.
However, you can use maxLength to get exact maximum characters you want to show, maxLines to set maximum number of lines the TextView can be expanded to and ellipsize to show that there are more words but it can not be fit in a single line.
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
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...
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.
NB: i set android:singleline=true
Try android:ellipsize="end", or if you want to fade, try android:fadingEdge="horizontal"
Use the android:ellipsize="end" in you XML layout file. You can also show the scrolling text by using android:ellipsize="marquee".