Milan Patel
Milan Patel

Reputation: 144

OnClickListener is not starting events in android studio

I am trying to create simple login application, but when I click on the register it's not firing events written in the onClickListener event.

I tried to register listener by register.setOnClicklistner(this) but that's not working either.

register.setOnClickListener(this);
        register.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Registration.this,"Password does not match",Toast.LENGTH_SHORT);
                String user = username.getText().toString().trim();
                String ema = email.getText().toString().trim();
                String pswd = password.getText().toString().trim();
                String pswd_c = password_confirm.getText().toString().trim();
                boolean flag1=false,flag2=false;
                if(pswd.equals(pswd_c)){
                    flag2 = true;
                }else {
                    Toast.makeText(Registration.this,"Password does not match",Toast.LENGTH_SHORT);
                }
                Pattern p = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
                Matcher m = p.matcher(ema);
                if(m.find()){
                    flag1=true;
                }else {
                    Toast.makeText(Registration.this,"Invalid Email address",Toast.LENGTH_SHORT);
                }
                if(flag1 && flag2){

                    long val = db.addUser(user,ema,pswd);
                    if(val>0){
                        Toast.makeText(Registration.this,"Registration Successful",Toast.LENGTH_SHORT);
                        Intent regSuccess = new Intent(Registration.this,MainActivity.class);
                        startActivity(regSuccess);
                    }else {
                        Toast.makeText(Registration.this,"Something went wrong!",Toast.LENGTH_SHORT);
                    }
                }
            }
        });

Upvotes: 1

Views: 113

Answers (2)

itsmebil
itsmebil

Reputation: 167

Add .show() to your toast or try to use AlertDialog to see if your OnClickListener works

Upvotes: 1

Uuu Uuu
Uuu Uuu

Reputation: 1282

Your Toast is missing show() method , You can use Log to check

Upvotes: 3

Related Questions