How To capitalize the letters in AutoCompleteTextView dynamically? - android

I am developing the application which consists of AutoCompleteTextView,here is my problem,How I can upper case the letters entering in AutoCompleteTextView.
I Don't want in xml: android:capitalize="characters"
I want to declare in Java code.

You can try like this..In your text watcher in ontextchanged change the text to upper case..and check if the new string in edittext is the old string which you converted to upper case...in order to avoid stackoverflow error..
String upper = mytextview.getText().toString().toUpperCase()
mytextview.setText(upper);

Try this in your code there are some other flags also which you can check and try.
tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

Related

Numbers separated by hyphen getting reversed in arabic string

My string looks like this "تغطية مباشرة.. ريال مدريد 2-0 مانشستر يونايتد", When I setText in a textview the numbers are getting reversed i.e(0-2 becomes 2-0).
I have tried setting text direction but it wasn't helpful.
Any ideas how to avoid the reversal?
Add this line in your activity onCreate method :
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

Numbers inside TextView getting reversed when formatted in RTL

Numbers inside TextView are getting reversed when formatted in RTL.
When numbers are at the end of a text inside a TextView they getting reversed. How can I solve this programmatically?
As an example, the numbers below are reversed:
They should be displayed like:
The misunderstand:
Digits in RTL languages like ARABIC should be written from RTL with the arabic digits to avoid any problems i.e: "تم إرسال رسالة نصية للرقم ١٢٣٤" Note that I wrote "رسالة نصية" NOT "SMS رسالة".
The problem and it's solution:
Mixing more than one direction languages required more steps, you need to tell the system "hey this is RTL word, add as it to sequence".
So you may need to do this implicitly, i.e:
\u200f + تم إرسال رسالة نصية إلى + number
Consider StringBuilder: It's very painful for developer to develop something for RTL language using plus(+) notation, this much confusing and error prone.
A better way:
builder.append("\u061C").append(" تم إرسال رسالة نصية لـ").append("\u200E").append("+0123456789")
Consider BidiFormatter: Utility class for formatting text for display in a potentially opposite-directionality context without garbling
Example:
String text = "{0} تم إرسال رسالة نصية لـ ";
String phone = BidiFormatter.getInstance().unicodeWrap("+961 01 234 567");
String result = MessageFormat.format(text,phone);
Now, result will be formatted properly.
More examples on how BidiFormatter work.
If you want to prevent the reversing of numbers for TextView when formatted in RTL, just specify android:textDirection="ltr" property for that specific TextView inside XML file. It will display number in the usual order.
Try this out
android:supportsRtl="false" in manifest file
and android:gravity="start" in your layout.
set the textview gravity to start
android:gravity="start"

Android EditText - Capitalize first letter of sentences using setText()

Folks,
I need to capitalize first letter of every sentence. I followed the solution posted here
First letter capitalization for EditText
It works if I use the keyboard. However, if I use setText() to programatically add text to my EditText, first letter of sentences are not capitalized.
What am I missing? Is there a easy way to fix or do I need to write code to capitalize first letters in my string before setting it to EditText.
The only thing the inputType flag does is suggest to the input method (e.g. keyboard) what the user is attempting to enter. It has nothing to do with the internals of text editing in the EditText view itself, and input methods are not required to support this flag.
If you need to enforce sentence case, you'll need to write a method which does this for you, and run your text through this method before applying it.
You can use substring to make this
private String capSentences( final String text ) {
return text.substring( 0, 1 ).toUpperCase() + text.substring( 1 ).toLowerCase();
}
Setting inputType doesn't affect anything put into the field programmatically. Thankfully, programmatically capitalizing the first letter is pretty easy anyway.
public static String capFirstLetter(String input) {
return input.substring(0,1).toUpperCase() + input.substring(1,input.length());
}

Android: can't read new line from database

i've got a database with a field in var_char(2000).
in this field there's text with some new line, like a normal text written:
hello
i am davide
bye
i put this text in a textview but i see the text like a unique line (hello i am davide bye), without newlines.
in iphone it is all normal and i've done nothing particular... but here no.
how can i?
i've tried with replace \n or replace \r\n o other things but without success.
Also with Html.fromHtml()
the singleLine(false) is deprecated, and it doesn't work.
also text doesn't work. it see the newline as a space
Try setting android:singleLine="false" to your textView.
Edit:
If this does not work check whether the string has a new line character using below code
char[] chararray= mString.toCharArray();
for(char temp:chararry){
int value = temp;
System.out.println(value);
}
Decimal value of Newline is either 10 or 13. While space character is 32.
Edit2 : I think TextView does not go to next line for \r which is 13.
So do
mString = mString.replaceAll("\r","\n");
did you try changing the datatype in sqlite?, your varchar to just text? if not, try doing so maybe it'll help
Try to disable the multi-line feature of the text view.
If you created the text view from an XML file, add this attribute to the text view :
<TextView
[...]
android:singleLine="false"
[...] />
If you created the text view programmatically, try to use the following method instead :
TextView myText = [...]
myText.setSingleLine ( false );

How to change color of a text using HTML tag in Android

I have a string which contain three words. I want to show the three words in same textview but in different line. For this I have used <br> tag. Now I want to show the last word in red color. I tried so many codes but nothing worked for me.
My code snippet is
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>")+
customerDetail[1]+Html.fromHtml("<br>")+
Html.fromHtml("<font color='#ff0000'>")+
customerDetail[2]+Html.fromHtml("</font>"));
Do like that:
code:
String toshowstring = customerDetail[0]+customerDetail[1]+
"<font color='red'>"+customerDetail[2]+"</font>";
viewHolder.cutomerinfo.setText(Html.fromHtml(toshowstring));
That's all you want.
^-^
//only one Html.fromHtml() method is enough
viewHolder.cutomerinfo.setText(
customerDetail[0]+Html.fromHtml("<br>"+customerDetail[1]+
"<br><font color='#ff0000'>"+
customerDetail[2]+"</font>"));
for Ref:

Categories

Resources