2012-02-04 16 views
0

我正在實現一個具有使用http post創建和發佈消息的功能的應用程序。我正在做的是,我從edittext獲取文本並將其添加到NameValuepair並將其附加到帖子網址。我的問題是在發佈消息之後,在我使用換行符的消息中顯示'n'。我的意思是,在輸入消息的時候,無論我按下Enter按鈕的哪個位置都顯示'n',而輸入時我可以放入換行符,但在發佈 後,它只顯示'n',整個身體只顯示單行。這是代碼。在Android中顯示新行的字符n

etMessage = (EditText)findViewById(R.id.etMessageCreate);  
etMessage.setSingleLine(false); 
etMessage.setInputType(etMessage.getInputType()|EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES); 
nameValuePairs = new ArrayList<NameValuePair>(10); 
nameValuePairs.add(new BasicNameValuePair("message",etMessage.getText().toString())); 
HttpClient httpclient = new DefaultHttpClient(); 
HttpPost request = new HttpPost(url); 
request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

這裏是xml。

<EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:drawable/editbox_dropdown_light_frame" 
    android:id="@+id/etMessageCreate" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_below="@id/etSubject" 
    android:gravity="top" 
    android:scrollbars="vertical" 
    android:inputType="textNoSuggestions|textVisiblePassword" 
    android:minHeight="100dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp"/> 
+0

你確定它沒有顯示\ n呢?這將是換行符的替代品! – theomega 2012-02-04 10:14:54

+0

它只顯示n .... – Aju 2012-02-04 10:47:45

回答

0

嘗試將此添加到您的XML佈局文件:
android:singleLine = "false"
android:inputType="textMultiLine"

我用這個和它工作得很好;)
希望這會有所幫助。

編輯: 好的,我沒有注意到,你正在設置singleLine爲false編程。 :)所以嘗試添加textMultiLine到 「的inputType」

:)

+0

不工作的兄弟 – Aju 2012-02-04 14:45:11

0

嘗試這樣做:

request.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); 
+0

setEntity()中只允許有一個參數。 – Aju 2012-02-04 14:44:51

+0

對不起,我的錯。編碼參數傳遞給'UrlEncodedFormEntity'的構造函數 – Jin35 2012-02-04 17:00:51