0
我想從編輯文本中獲取文本,並將其顯示在TextView.But中,當我使用getText()獲取文本時,它會給我一行文本。如何按照原樣在多行EditText中輸入文本。請給我指導?檢索EditText多行文字,因爲它是Android?
我想從編輯文本中獲取文本,並將其顯示在TextView.But中,當我使用getText()獲取文本時,它會給我一行文本。如何按照原樣在多行EditText中輸入文本。請給我指導?檢索EditText多行文字,因爲它是Android?
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中保持換行符。你可以自己嘗試。
也許如果您發佈您的代碼(至少相關位),我們可以幫助您。