膨胀的 EditText 的内容
我很难弄清楚如何从膨胀的 EditText
中将 getText()
作为可读字符串。
我有一个布尔方法来检查某些内容,因此,在 onCreate 方法中我这样称呼它
if(method) {
if(booleanVariable) {
LayoutInflater factory = LayoutInflater.from(MyActivity.this);
View child = factory.inflate(R.layout.password, null);
mPassword = (EditText)child.findViewById(R.id.password);
}
}
然后这就是我尝试检索文本的部分:
private View.OnClickListener btnLoginListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mPassword!=null) {
if(mPassword.getText().toString()==password) {
// LOGIN OK
} else {
// NOT OK
}
}
}
结果:
07-11 15:39:53.098: VERBOSE/Project(1239): mPassword: <b>android.widget.EditText@43d3ba98</b> password: 329349
I'm having a hard time figuring out how to getText()
as a readable String from a inflated EditText
.
I have a boolean method that checks something, so, in the onCreate method i call it like this
if(method) {
if(booleanVariable) {
LayoutInflater factory = LayoutInflater.from(MyActivity.this);
View child = factory.inflate(R.layout.password, null);
mPassword = (EditText)child.findViewById(R.id.password);
}
}
Then thats the part where i try to retrieve the text:
private View.OnClickListener btnLoginListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mPassword!=null) {
if(mPassword.getText().toString()==password) {
// LOGIN OK
} else {
// NOT OK
}
}
}
Result:
07-11 15:39:53.098: VERBOSE/Project(1239): mPassword: <b>android.widget.EditText@43d3ba98</b> password: 329349
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还是个新手,对 EditTexts 不太了解,但通常在 Java 中我们不会对字符串使用 == ,因为它们是对象。
会更正确。
Im still quite new and I don't know too much about EditTexts but normally in Java we don't use == for Strings since they are objects.
would be more correct.