2016-08-08 31 views
0

假設我有一個字段,我將得到full_name。所以名字和姓氏之間應該有一個空格。但是當我輸入像 - 湯姆克魯斯 ,,,它給錯誤,顯示。但它需要TomCruise很好。這是我的代碼。我也沒有任何修剪功能。所以爲什麼我不能節省空間。從我的android應用程序保存數據到mysql時,它刪除空格

activity_main.xml中

<TextView 
    android:text="full name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

MainActivity.java 我只是給cruicial一部分。

private EditText editTextName; 

editTextName = (EditText) findViewById(R.id.editTextName); 

String name = editTextName.getText().toString(); 

String urlSuffix = "?name="+name+"&username="+username+"&password="+password+"&email="+email; 

我發送到PHP網站,然後保存它。如果我刪除單詞之間的空格,則工作正常。

+0

爲什麼不使用直接的SQL API來處理數據庫連接? –

+0

我是新來的android .. –

回答

0

只需將空格字符替換爲「%20」即可。 name = name.replace(「」,「%20」);

1
private EditText editTextName; 

editTextName = (EditText) findViewById(R.id.editTextName); 

String name = editTextName.getText().toString(); 


String urlSuffix = "?name="+name+"&username="+username+"&password="+password+"&email="+email; 

// Spaces are not allowed in urls, to represent it we use %20, add the below line to replace all spaces with "%20". 

urlSuffix = urlSuffix.replace(" ", "%20"); 
相關問題