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
Related
I am making a calculator and I want to make sure that user is able to enter a "Negative Decimal Number" I see the option in the xml file separately for example in order to put the Decimal Number, the EditText's inputType must be numberDecimal and for negative number the inputType must be "numberSigned" but I need both. If I choose inputType as "text" then user is able to enter anything which throws an exception if it's not a number. I am not sure how to fix that either.
You can use both with the "|" operator. Just specify "numberSigned|numberDecimal".
Add this in the layout of the EditText:
android:digits="0123456789-."
You can specify more there, for example if you want the user to input sin() functions.
As #a11n says, you can use the pipe operator to specify both:
<EditText
...
android:inputType="numberSigned|numberDecimal"
... />
Valid numbers: positive and negative decimal and whole numbers.
Some phones have the decimal and negative in the same button and makes it unable to do negatives. I figured out a way you could separate the buttons by simply adding:
android:inputType="numberSigned|numberDecimal|textPersonName"
android:digits="0123456789.-"
That way you still have the number keyboard layout but the negative and decimal buttons will be separate and you cannot use any other digit that messes up the app.
I have an edittext field. As I type and characters exceed the maxlength of it there appears a new row to continue typing. However, I want to avoid this behavior since there is map below it which is going down relatively.
I don't want to restrict the maxlength as well.
Can someone explain how do I solve this problem?
define following parameters in your xml under the edittext tag:
android:singleLine="true"
Correct me if Im wrong, but is't singleLine="true" depricated?
android:lines="1"
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...
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.
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.