Categories: java, android, xml, android-layout

Setting Lenght Limit in editText in Java

1 answer

In my Android app, I will take the name of the person with an editText. Then, I will send it to a textView to show that in the subsequent activities. But, I have a limited area. That's why I have to limit the length of the name. In XML, we can restrict the character length with a code called maxLength. However, I don't want to use it because I want to limit the text within the design limits.

I will visualize the reason why I don't want to use this method. Let's imagine that the person wants to use 8-Z(ZZZZZZZZ) as a name; on the other hand, another person wants to use 8-i(iiiiiiii). Of course, their actual length will be different in design. So, I want to limit the name based on its length on design instead of its character length. I'm waiting for your contributions and suggestions.

All answers to this question, which has the identifier 61238719

The best answer:

You can use one line TextView with scaling the TextSize and fit the whole text in its layout bounds.

<TextView     android:layout_width="match_parent"     android:layout_height="wrap_content"     app:autoSizeTextType="uniform"     app:autoSizeMinTextSize="8dp"     app:autoSizeMaxTextSize="12dp"     app:autoSizeStepGranularity="1dp"      android:singleLine="true"     android:maxLines="1"/> 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data