Android Studio solves SetText Chinese garbled problem

Source: Internet
Author: User

When I use the android Studio compiler, I always encounter a lot of garbled problems. The first garbled problem is defined in the layout file inside the EditText, in the code need to get the content into the edittext inside, this time if there is a Chinese language will appear garbled, the code is as follows:

Super.oncreate (save);        Setcontentview (R.layout.second);        EditText show = (EditText) Findviewbyid (r.id.show);        ComponentName comp = getintent (). Getcomponent ();        Show.settext ("component package named" +comp.getpackagename () + "component class named" +comp.getclassname () ");

The result of the display is that the package name for these Chinese characters is garbled and cannot be displayed properly. A good solution is to put the text in the String.xml, in the code to refer to it, the code is as follows:

Show.settext (GetString (r.string.  The component package is named +comp.getpackagename () +getstring (r.string.  The component class name is ) +comp.getclassname ());
This solution for less Chinese, is very convenient and fast, can avoid a lot of garbled problems.


Many also have comments on the Chinese code, in the lead from others, the general will appear garbled problem, this time, for the running code location, click on the lower right of the code conversion, converted to UTF-8 format, generally can solve the problem.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Studio solves SetText Chinese garbled problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.