我正在實現一個具有使用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"/>
你確定它沒有顯示\ n呢?這將是換行符的替代品! – theomega 2012-02-04 10:14:54
它只顯示n .... – Aju 2012-02-04 10:47:45