如何在 TextView 中显示 EditText 字段文本

How to display the EditText fields text in the TextView

最近我只是想创建一个 mems generator 应用程序,是的,我一直在关注新的波士顿,在 buckey 中使用 2 个片段创建它们,在这里我只想在一个主程序中做 activity,但我只是不知道如何从编辑文本字段中检索文本并将文本视图的文本设置为它。我知道这是一个新手问题,但我仍然不知道如何编码,所以请帮忙...

我刚刚导入了一些小部件、视图等并修改了创建函数,我的创建函数是:

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

使用这个简短的例子来理解这个概念

store=ret.getText().toString();

show.setText(商店);

说明

ret: 是编辑文本字段的名称;

store:用于保存从 ret(文本字段)获得的任何内容

show.setText(store) 在文本视图中显示结果

只需这样做:

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

试试这个来获取 EditText 字段的文本:

CharSequence text = topText.getText();

并为 textView 设置上面的文本:

top.setText(text);

这个问题已经回答:

"Use getText() on your EditText object".

Get Value of a Edit Text field

下次快速搜索 ;)