开发者

Problem with onClickListener

开发者 https://www.devze.com 2023-03-28 21:37 出处:网络
this actually does nothing when i click the button. The button is like: Button Confirmar = (Button)findViewById(R.id.btConfirma);

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开发者_StackOverflow中文版="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


i guess you have to set the result before calling the finish

...
Intent i = getIntent();
Bundle bD = new Bundle();
bD.putStringArray("Login", new String[] {edLogin.getText().toString(), edSenha.getText().toString()});
i.putExtras(bD);

setResult(RESULT_OK, i);

finishActivity(555);

check this link if you have any doubt. LINK


Put a breakpoint on first line inside onClick listener, run on debug mode and see where it goes on the code.


That's a strange error. I'd try to maybe setOnClickListener(this) and let your activity implement onClick(View). Otherwise you can add android:onClick tag to the xml button object.

0

精彩评论

暂无评论...
验证码 换一张
取 消