我有一個EDITTEXT在搜索字符串填寫:的Android EditText上沒有返回正確的UTF-8文本
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search_input_edittext"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:padding="10dp"
android:background="@drawable/add_to_cart_btn"
android:text="@string/search"
android:id="@+id/search_search_btn"
android:stateListAnimator="@null"
android:layout_gravity="center_horizontal" />
</LinearLayout>
但越南詞,我輸入沒有正確getText().getString()
。它應該是(我輸入手動此一)
銅
,但我從代碼有:
EditText search_edittext = (EditText) v_iew.findViewById(R.id.search_input_edittext); //v_iew is from inflating for `AlertDialog`
search_edittext.getText().toString();
是像下面的圖片:
我認爲他們是不同的編碼。掛鉤必須在「u」之上。但是,如果我複製整個單詞並粘貼到任何編輯器,它顯示完全相同。這是個什麼樣子,當我在這裏貼吧,如:
銅
,這是,如果我複製鉤什麼只發生
̉
他們看起來相同,但EditText
不能用於進一步的作品。
如果我從互聯網複製單詞並粘貼到搜索字段,它的工作原理!所以這是我的輸入法引起的問題。試圖尋找轉換他們到unicode(\ xxxx),但沒有運氣。
任何人有任何想法如何將輸入轉換爲「正常格式」?感謝您的時間!
這是我的代碼爲我的GET方法。你應該在哪裏放置UTF-8? 'HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(params [0]); HttpResponse response = httpclient.execute(httppost); jsonResult = inputStreamToString( response.getEntity()。getContent())。toString(); jsonResult = jsonResult。子串(6);' –
我修改了一下代碼。您當前執行POST請求的方式似乎沒有任何有效負載。 StringEntity將您的POST負載/參數(NameValuePair或JSON對象)編碼爲UTF。 – fluffyBatman
哦對不起,忘了提。 params [0]是GET參數的整個鏈接。 –