0

I don't use unicode characters in my android-textview.How can I do this?

my xml :

<?xml version="1.0" encoding="utf-8"?>

and I don't use unicode characters in android textview,edittext,....

CompEng
  • 7,161
  • 16
  • 68
  • 122
  • tv.settex("şile"); it seems like this : ?ile – CompEng Feb 02 '12 at 09:07
  • Have you maybe got an encoding problem in your source code? Does writing the string as `"\u015File"` make any difference? – bobince Feb 02 '12 at 10:27
  • you dont understand me ? – CompEng Feb 02 '12 at 14:23
  • To be honest no, I don't. I don't know what you're trying to do or what the XML prolog has to do with a TextView. But if you are writing `tv.settex("şile");` in your source code then you have to make sure the source is being interpreted using the right encoding you've saved it in, otherwise you will get `?ile`. Using a string literal escape `"\u015File"` avoids that problem. – bobince Feb 03 '12 at 13:42
  • Thanks fir answering.i mean not specially sile i want . I want all unicode chars to be seen .so it s changed dinamically .i dont want write static .how can i fix it – CompEng Feb 03 '12 at 14:28
  • Well, any other strings in your source should either be written using an appropriate encoding, or as `\u` hex-escapes in the same way as above. If you have other strings getting into the application, you'll have to look at how you are reading them; with no code here it's impossible to guess. The problem is not in `TextView.setText`. – bobince Feb 03 '12 at 14:45
  • I randomly write words in my .txt. there are many unicode chars words, what can I do? ı dont want to write all words which include unicode chars, can ı tell? I must do something that all that kind of words fixed dinamicallly – CompEng Feb 03 '12 at 18:51
  • What .txt? How are you reading the characters into your application? I suggest whatever you are editing, you need to match the encoding you're using to save it with the encoding you're using to read it. For sanity, save as UTF-8. – bobince Feb 03 '12 at 23:21
  • I write this : TextView.setText("\u015File") and yes it is seen "şile" but I write "\u015File" this in my .txt and in code I write extView.setText(x) ..: x is reading .txt and getting "u015File" but now it seems "u015File" not "şile" what can ı do? – CompEng Feb 04 '12 at 14:47
  • I write this : TextView.setText("\u015File") and yes it is seen "şile" but I write "\u015File" this in my .txt and in code I write extView.setText(x) ..: x is reading .txt and getting "u015File" but now it seems "u015File" not "şile" what can ı do? – CompEng Feb 04 '12 at 14:48
  • `\u015F` are string literal escapes, they only work in code. You need to read your text file using the same encoding you used to save it. Make sure to save it in your text editor as UTF-8. I don't know how you are reading the text file as you have not posted that piece of code. – bobince Feb 04 '12 at 15:03
  • words.txt : a\U00E7 \U015Fu ta \U0069\U015F yo : this is my txt. and this my code : inputStream = getResources().openRawResource(R.raw.words.txt); Random rndm=new Random(); int jj=1+rndm.nextInt(kelime_sayisi); int ast=0; inputreader = new InputStreamReader(inputStream); buffreader = new BufferedReader(inputreader); String line;StringBuilder text = new StringBuilder(); try {while ((line = buffreader.readLine()) != null) { if(jj==ast){ text.append(line); break; } ast++; } } catch (IOException e) { return null;} textview.settext(text.toString()); – CompEng Feb 04 '12 at 15:11
  • When I write in code tv.settext("\u015File") it is well but when I write code which read in .txt and tv.settext(text) which text contains "\u015File" it is not work it is seen "\u015File" – CompEng Feb 04 '12 at 15:17
  • `\u`-escapes are only for code, don't include them in a text file; type the character directly and save the file in an encoding that includes the desired characters (I strongly recommend UTF-8). `new InputStreamReader(inputstream)` without the `charset` argument you will get the default encoding; you should never rely on the default encoding. Pass the name of the encoding you have used to save the text file as the charset argument, eg `new InputStreamReader(inputStream, "utf-8")`. – bobince Feb 04 '12 at 20:33
  • I try InputStreamReader(inputStream, "utf-8") but it is not working. what can ı do – CompEng Feb 05 '12 at 09:44
  • 4
    Again, please save your text file as UTF-8. You cannot read a file that is not saved as UTF-8, as UTF-8. The thing that you have to do to ensure that a text file is readable by a UTF-8 Reader is to save it as UTF-8. UTF-8 is the encoding you should choose in your text editor when saving a file, to ensure that a program that reads it as UTF-8 will get the correct characters. The best thing to do is to choose UTF-8 as the encoding under which you save the file. If you do not have a text editor that lets you choose to save as UTF-8, get a new one that is a bit better at saving as UTF-8. – bobince Feb 05 '12 at 11:34
  • answer question @bobince and ı tick your answer – CompEng Feb 05 '12 at 13:41
  • last of my question ı cant ask question anymore whenI can ask again – CompEng Feb 05 '12 at 13:46

1 Answers1

2

Summary of comment thread:

  1. Save .txt file containing şile as UTF-8. (For Notepad, best: UTF-8 without BOM.)

  2. Load from code using a new InputStreamReader(inputStream, "utf-8").

bobince
  • 528,062
  • 107
  • 651
  • 834