2010-11-25 8 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); 
    } 
    }; 
} 

토스트와 텍스트 뷰 줄 바꿈을 계속 둘. 너 스스로해볼 수있어.

아마도 코드를 게시하면 (적어도 관련된 비트) 우리는 당신을 도울 수 있습니다.

관련 문제