2010-11-25 19 views

回答

0

Rajendar,

我不明白你爲什麼會遇到這個問題。當你從EditText獲得一段文本時,它應該保持「格式化」,如換行符。

例如,試試這個代碼(我自己測試過)!

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

<EditText 
    android:id="@+id/et" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 

<TextView 
    android:id="@+id/tv" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello" 
    /> 

<Button 
    android:id="@+id/m_button" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    /> 
</LinearLayout> 

main.java

public class MainTest extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button button = (Button) findViewById(R.id.m_button); 
     button.setOnClickListener(btnListener); 
    } 


    //button listener 
    private OnClickListener btnListener = new OnClickListener() { 

    public void onClick (View view) { 

     EditText et = (EditText) findViewById(R.id.et); 
     String str = et.getText().toString(); 

     Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show(); 

     TextView tv = (TextView) findViewById(R.id.tv); 

     tv.setText(str); 
    } 
    }; 
} 

兩個麪包和TextView中保持換行符。你可以自己嘗試。

也許如果您發佈您的代碼(至少相關位),我們可以幫助您。