-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);