此代码无效,我在1小时前启动了android开发:)
Button btn = (Button) findViewById(R.id.button);
final EditText edt = (EditText) findViewById(R.id.editText);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Editable ec = edt.getText();
Toast.makeText(MainActivity.this,"HELLO !"+ec,Toast.LENGTH_SHORT).show();
}
});
我该如何解决这个问题?
谢谢。
答案 0 :(得分:2)
Button btn = (Button) findViewById(R.id.button);
final EditText edt = (EditText) findViewById(R.id.editText);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,"HELLO !"+edt.getText().toString(),Toast.LENGTH_SHORT).show();
}
});
答案 1 :(得分:1)
试试这段代码:
String txt = ed1.getText().tostring();
Toast.makeText(MainActivity.this,"HELLO!"+txt,Toast.LENGTH_SHORT).show();