onClickListener 的问题
当我单击按钮时,这实际上没有任何作用。 按钮就像:
Button Confirmar = (Button)findViewById(R.id.btConfirma);
Confirmar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String Login = edLogin.getText().toString();
String Senha = edSenha.getText().toString();
if(Login.length() == 0 || Senha.length() ==0) {
Toast.makeText(getuser.this, "Por favor preencha o login e a senha!", Toast.LENGTH_LONG).show();
return;
}
if (chkKeep.isChecked() && (edLogin.getText().toString() != Settings.getUser() || edSenha.getText().toString() != Settings.getPass())) {
Settings.setUser(edLogin.getText().toString());
Settings.setPass(edSenha.getText().toString());
Settings.setKeepUser(chkKeep.isChecked());
jXML.updateConfigXml();
}
Intent i = getIntent();
Bundle bD = new Bundle();
bD.putStringArray("Login", new String[] {edLogin.getText().toString(), edSenha.getText().toString()});
i.putExtras(bD);
finishActivity(555);
}
});
按要求 -->按钮 XML:
<Button android:layout_width="180dip" android:layout_height="wrap_content" android:id="@+id/btOkLogin" android:text="Confirmar"></Button>
已解决: 必须在 finish() 之前使用 setResult(ResulCode, Intent); 回答者:@Sam-Quest
this actually does nothing when i click the button.
The button is like:
Button Confirmar = (Button)findViewById(R.id.btConfirma);
Confirmar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String Login = edLogin.getText().toString();
String Senha = edSenha.getText().toString();
if(Login.length() == 0 || Senha.length() ==0) {
Toast.makeText(getuser.this, "Por favor preencha o login e a senha!", Toast.LENGTH_LONG).show();
return;
}
if (chkKeep.isChecked() && (edLogin.getText().toString() != Settings.getUser() || edSenha.getText().toString() != Settings.getPass())) {
Settings.setUser(edLogin.getText().toString());
Settings.setPass(edSenha.getText().toString());
Settings.setKeepUser(chkKeep.isChecked());
jXML.updateConfigXml();
}
Intent i = getIntent();
Bundle bD = new Bundle();
bD.putStringArray("Login", new String[] {edLogin.getText().toString(), edSenha.getText().toString()});
i.putExtras(bD);
finishActivity(555);
}
});
As asked --> Button XML:
<Button android:layout_width="180dip" android:layout_height="wrap_content" android:id="@+id/btOkLogin" android:text="Confirmar"></Button>
SOLVED: Had to use setResult(ResulCode, Intent) before finish();
Answered by: @Sam-Quest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想您必须在调用完成之前设置结果,
如果您有任何疑问,请检查此链接。 链接
i guess you have to set the result before calling the finish
check this link if you have any doubt. LINK
在 onClick 侦听器内的第一行放置一个断点,在调试模式下运行并查看它在代码中的位置。
Put a breakpoint on first line inside onClick listener, run on debug mode and see where it goes on the code.
这是一个奇怪的错误。我会尝试
setOnClickListener(this)
并让您的活动实现onClick(View)
。否则,您可以将android:onClick
标记添加到 xml 按钮对象。That's a strange error. I'd try to maybe
setOnClickListener(this)
and let your activity implementonClick(View)
. Otherwise you can addandroid:onClick
tag to the xml button object.