Is there a way to let a user write in single and multiple lines in EditText, inputType textMultiline is for Multiline only and text for single line only, is there a way to have both?
Multiline attribute normally allows a user to take advantage of multilines. But incase u want to achieve that, the alternative would ve to use teo edittexts. Give one the multiline attribute and the keep singleline for the other. Since single line takes precidence, you might want to hide the multiline edittext onCreate. Set a length (number of characters) at which you the user should now be switched to the multiline edittext. Save the input added at the time, hide the singleline editText then show the multiline after you have set the original text from the singleline edittext.
I hope that helps.
Related
I have a edittext on which i want to add special character "!" after every 10 characters.
So for example if i write :
9090909090!164960375830!0583948
And when i remove text from then it will auto remove "!".
I have tried addTextChangedListener but wont able to achieved it.
How can i get it ?
I would like to set the background of edittext per line as opposed to android's block style of setting up the background i.e when a user writes some text, I should get the text entered by a user, split it into lines and set a background color for each line. Check the attached picture for references.
I've not been able to figure out how to achieve the same, please help. This is what I've done so far, thanks in advance.
Desired picture [1]: https://i.stack.imgur.com/LhpTQ.jpg
String allLines = userInput.getText().toString(); // userInput is an edittext field
String[] lines;
String linelimit = "\n";
lines= allLines.split(linelimit);
//this gives the lines in the user input text][1]][1]
Use 2 or more separate TextView/EditText instead. If number of lines are different during execution then add Textview/EditText dynamically in LinearLayout.
It is not possible in any view (that I know of) because there is only one background for every view, or EditText and cannot be separated for each line.
If you are using an EditText that user can edit, then you will have to calculate width of EditText as text changes and if its width exceeds a limit, you can add another EditText below it.
I am currently trying to fix my problem with string length at buttons, in android application. So i parse string and then set it as button text. But if one text is bigger then 9 characters or 10 it gets displayed out of the button overlay. I know i could make text smaller but this is not good solution because i already have small text.
So what you guys recommend for example if i have:
String text = "ThisIsSomeRealyLongText";
How can i split this string in 2 lines or when i reach character number 9 just use /n (to break text)?
Using too much text on a button is never a good idea. You should think about using an icon, or shorter text with (if needed) more explanation text somewhere else. Remember,the best UX will be the one with the least amount of reading involved.
Using regex you can do this. It will break the string into 9 characters per line.
text = text.replaceAll("(.{9})", "$1\n");
Use
(new line):
android:text = "ThisIsSome
RealyLongText"
But in code, you can just use \n. You can define in ../res/values/strings.xml:
<string name="longname">ThisIsSome\nRealyLongText</string>
then set the text for you button
android:text="#string/longname"
In my application, Im having a Textview containing text in this style:
"123131 (Ø 374)"
On small devices, the text reaches the viewborder causing a new line at one of these spaces. In some cases, this makes the text look like this:
"123131 (Ø
374)"
Is there a way to force the new line to the first whitespace without using 2 TextViews? Isnt there some kind of "protected white space" or something like this?
"123131
(Ø 374)"
regards
danijoo
I solved it by recplacing all whitespaces but one with the unicode code for a nonbreaking whitespace:
"123131 (Ø\u00a0374)"
What I'd do is:
Implement a custom TextView with a listener when Ellipsis is triggered:
http://thanksmister.com/2012/10/16/android-textview-with-ellipsis-listener/
Then, when receiveing the listener, programmatically adding a '\n' character right before the '(' character.
Remember to set that TextView to be multi line.
I have a number of editText's in my view and I want to be able to make some adjustments to the keypad that points up for the user when they highlight the EditText.
In particular
- Making a capitals only keypad?
- Removing the auto-correct feature?
- Adding non-english characters to the first screen of the keypad e.g. "ñ"
Is there a simple approach for changing this keypad?
In general, you don't have that much control of the on-screen keyboard that is displayed to the users. However, turning off autocorrect and making all characters capitals is a possibility, you simply need to set the android:inputType attribute in your XML. Here are the values that you can use (you can also OR | them). It would look like android:inputType="textCapCharacters|textNoSuggestions".
I wouldn't worry about the Ñ or other weird characters. Most of those are easy to get by just long pressing on a key (in this case, the N).