Android encoding a string and display in textView - java

I have an array of strings which are in latin and have some letters which are turned into "?", I need them to display correctly.
String[] asd= {"Srećni nikad ne razmišljaju o sreći."};
in "asd" I have strings which I need to display correctly in TextView on my android device, but every "ć", "š" turns into "?".
textView.setText(asd[0]);
I am using Android Studio. Thanks

In Android Studio there is two options for encoding you need to check
1- your project encoding
2- your IDE encoding
you will find them under setting
Please make sure also not to hard code any strings you have to put them in string xml files

Try using Unicode, here is a table for your convenience ;
http://unicode-table.com/en/#00E8
And chech this question, it may help;
Unicode characters not displayed in TextView.setText

You are supposed to put strings like that into your XML and get them from there. It's a good idea too, since that allows you to have several languages, yet using the same code. Read more here

Related

How to start first line in text view(paragraph) in middle - android

I am new to Android. I have a paragraph in string which looks like below
String my_paragraph ="Software is a set of instructions, data or programs used to operate computers and execute specific tasks. It is the opposite of hardware, which describes the physical aspects of a computer. Software is a generic term used to refer to applications, scripts and programs that run on a device."
textView.setText(my_paragraph);
I want to display it in the Text View like this below image:
But what I got is I added below
I want the first line in text view(paragraph) should starts in the middle. I don't want to add leading spaces in string. I don't know how to achieve this. Please help me with some solutions.
Android has libraries that can do this for you. I found an old post with a great how to use the SpannableString and LeadingMarginSpan libraries.
The question can be found at: What is Leading Margin in Android?
try to add \t or \u0009 (tabulator character) at the begining of String - this is a symbol of default indetation for paragraphs
textView.setText("\u0009" + my_paragraph);

Arabic pronounce symbol not showing correctly

Im trying to put text with arabic letters, some of the text working correctly, and the others symbol is showing weirdly.
Some of the letters just font issue, i can still tolerate if it fix all the mistakenly displayed symbol.
I tried to change font, putting on string, custom font, but it does not work. Any ideas guys ?
i put the pull the text from string res currently.
here is the wrong letters.
here is the correct letters
You should use custom font for your view..
For example this view support TextView custom font from assets.
If you were wondering what encoding would be most efficient:
All Arabic characters can be encoded using a single UTF-16 code unit (2 bytes), but they may take either 2 or 3 UTF-8 code units (1 byte each), so if you were just encoding Arabic, UTF-16 would be a more space efficient option.

Use OCR Text reader to save the text

I followed the OCR text reader guide on Codelabs (https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#0).
Now, I would like to save, a single portion of the text that I am scanning.
I tried with reducing width, and height of the preview; but it doesn't work, the APK crashes (at least on the only device I have to test it).
I am completely new to Java, and Android development, but my Internship mentor said to do this; completely alone, with zero help (as no one in the company knows about development).
So, the app opens, it recognizes text. Now, I would like to to know if there is a way to take that text, and save it (XML or TXT file).
I tried to look in the code, and see if at some point, the text read is saved in a variable or something; but it looks like a live preview, done trough the Google's dependencies (or a similar process).
I am not sure, but this might be off topic, as it is similar to an open question, but I am giving details on what I have done so far, and what I have tried.
Thanks.
The detected text is displayed in the OcrGraphic.draw(Canvas) method. There, it is returned as a TextBlock. You can call textBlock.getComponents() to get the lines and textBlock.getComponents() again to get each individual word (as a Text object).
Then you can convert it to a string and write the text to a file if you would like.

Text inside button too big autosize?

The problem I am having is when changing localisation on the application the character length for some words is longer than the previous language therefore there are sizing issues with the buttons as they were initially made just for English.
English Locale Screenshot
Spanish Locale Screenshot
I know I am able to add android:maxLines="1" but this wouldn't solve my issue as the text is too large. I tried using a textview auto sizer for the text size but this hasn't solved the issue.
Does anyone have suggestions?
Thanks to #AdeelTurk for providing this answer. I was able to use autofittextview with my buttons but it was complex here is an example of how I used it with a LinearLayout which usually don't work with this API.

How to show special characters in Android?

I am developing a native app which consists of some mathematical formulas.
Formulas will be like.........
I want to display such formulas in my application, but i don't how to use these special characters in Android. I want to display each formula individually in a list view...... If i am copying formula & if i am setting text to text view means it is showing like
txtv.setText("\\cos^2\\theta + \\sin^2\\theta = 1\\! ");
and getting output in the same pattern. So, can anyone help me how to use these mathematical special characters in Android..
Sorry, there are not a lot of different solutions..
There are no 'magical answer", here are some different ways to achieve what you want.
1) Using a webview with some Javascript
2) using a server to produce a picture of the formula.
3) Using a 9.png file embededd in your app with the square root symbol and display it as textview background
4) Drawing a canvas with all your text and symbols
5) using Hexadecimal code: http://htmlhelp.com/reference/html40/entities/symbols.html
http://tlt.its.psu.edu/suggestions/international/bylanguage/mathchart.html
6) Maybe other ideas, but definitely no way to achieve a 300 formula listview in a easiest way.
This one seem quite good and works in Android without any issue: http://mathscribe.com/author/jqmath.html
Edit:
You can run this inside a WebView, you don't need any webapp.

Categories

Resources