我是编程语言的新手。在android studio中,当用户按下按钮时,我试图从EditText中获取文本显示在TextView上。但它出错了。有人帮我吗?拜托,谢谢。
TextView welcome_lbl;
EditText enter_text;
Button welcome_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
welcome_lbl = (TextView) findViewById(R.id.welcome_lbl);
enter_text = (EditText) findViewById(R.id.enter_text);
welcome_btn = (Button) findViewById(R.id.welcome_btn);
welcome_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
welcome_lbl.setText(enter_text.getText().length());
}
});
}
答案 0 :(得分:0)
String text = enter_text.getText.toString();
welcome_lbl.setText(文本);
或者按照你的方式,
welcome_lbl.setText(enter_text.getText.toString());