我是Android编程新手。我一直在收到错误,无法找到任何显示输入字符串的解决方案。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText namex = (EditText) findViewById(R.id.username);
namex.getText().toString();
final EditText passwordx = (EditText)findViewById(R.id.password);
passwordx.getText().toString();
Button button = (Button)findViewById(R.id.signin);
button.setOnClickListener(
new Button.OnClickListener() {
@Override
public void onClick(View v) {
TextView name = (TextView)findViewById(R.id.Dispname);
name.setText(namex);
TextView password = (TextView)findViewById(R.id.Disppassword);
password.setText(passwordx);
}
}
);
}
非常感谢。提前谢谢!
答案 0 :(得分:0)
您正在做的是传递EditText
数据类型参数而不是String
,所以,试试这个
name.setText(namex.getText().toString());
password.setText(passwordx.getText().toString());
答案 1 :(得分:0)
更改以下代码,您将EditText
的引用设置为TextView
Button button = (Button)findViewById(R.id.signin);
button.setOnClickListener(
new Button.OnClickListener() {
@Override
public void onClick(View v) {
TextView name = (TextView)findViewById(R.id.Dispname);
name.setText(namex.getText().toString());
TextView password = (TextView)findViewById(R.id.Disppassword);
password.setText(passwordx.getText().toString());
}
}
);