2015-11-07 99 views
-2

我想在android中傳遞一個字符串到textview中(我在下面做了一個嘗試)我只是希望它把文本從文本視圖中分配給一個字符串輸出textview中的字符串。任何幫助將是偉大的!我需要傳遞一個字符串到android中的textview字符串

String str; 
EditText e1 = (EditText)findViewById(R.id.input); //take text assign to e1 
str = e1.getText().toString() //take text from e1 and assign it to string str 
TextView str= (TextView)findViewById(R.id.output);// 

回答

2

試試下面的代碼:

// Initialize e1 
EditText e1 = (EditText) findViewById(R.id.input); 

// Take text from e1 and assign it to str 
String str = e1.getText().toString(); 

// Initialize out 
TextView out= (TextView) findViewById(R.id.output); 

// Set text in str to EditText out 
out.setText(str);