-1

我剛剛嘗試創建一個mems生成器應用程序,是的,我一直在關注新的bostons,並在那個buckey中使用2個片段創建它們,在這裏我只是想做在一個單一的主要活動,但我只是不知道如何從編輯文本字段中檢索文本並將文本視圖的文本設置爲它,我知道它的一個新手問題,但我仍然不知道如何代碼,所以請幫助.. !!!如何在TextView中顯示EditText字段文本

我剛剛進口了一些小工具,意見等,並做了一些修改上創建功能,我上創建功能是 -

public class MainActivity extends AppCompatActivity { 

public static EditText topText; 
public static EditText bottomtext; 
public static TextView top; 
public static TextView bottom; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    topText = (EditText) findViewById(R.id.topedit); 
    bottomtext = (EditText) findViewById(R.id.bottomedit); 
    top = (TextView) findViewById(R.id.top); 
    bottom = (TextView) findViewById(R.id.bottom); 
    Button myButton = (Button) findViewById(R.id.button); 
    myButton.setOnClickListener(
      new Button.OnClickListener() { 
       public void onClick(View V) { 
        top.setText((CharSequence) topText); 
        bottom.setText((CharSequence) bottomtext); 

       } 
      } 

    ); 
} 

回答

1

只要做到這一點:

if(topText.getText()!=null){ 
top.setText(topText.getText().toString()); 
} 
if(bottomtext.getText()!=null){ 
bottom.setText(bottomtext.getText().toString()); 
} 
+0

來到之前實現閱讀還機器人的完整文檔,你會發現在文檔中幾乎所有的東西。您可以參考http://developer.android.com – Aakash

+0

感謝他只是一些小的修改,即顛倒null和topText.getText()和底部也一樣 - if(null!= topText.getText( )){ top.setText(topText.getText()。toString()); (null!= bottomtext.getText()){ } bottom.setText(bottomtext.getText()。toString()); } –

+0

高興地幫助,請標記爲正確的,如果我的回答是有幫助的 – Aakash

0

使用這個簡單的例子來理解這個概念

店= ret.getText()的toString();

show.setText(store);

說明

RET:是編輯的文本字段的名稱;

店:是用來裝東西的RET(文本域)得到

show.setText(店),結果顯示在TextView的

1

嘗試此得到的EditText字段中的文本:

CharSequence text = topText.getText(); 

而對於設置上述文本TextView中:

top.setText(text);