为什么按下android中的按钮不能激活toast?

TuG*_*llo 1 android android-edittext android-button android-toast

在按照以下条件单击"boton_continuar"按钮时,我正在尝试显示吐司:EditExt vacuum(numero_celular)和ckeckbox(check)选中no.这是我的代码

boton_continuar.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        //Verificamos que se halla clikeado y se halla ingresado
        if(check.isChecked() && numero_celular.getText().length() != 0){

            Intent intent = new Intent(RegisterActivity.this, PrincipalActivity.class);
            startActivity(intent);
        }else{
            Context contexto = getApplicationContext();
            if(!check.isChecked()){                 
                Toast.makeText(contexto, "Debe aceptar los términos", 2000);
            }
            if(numero_celular.getText().length() == 0){
                Toast.makeText(contexto, "Debe ingresar su número", 2000);
            }
    }
}});
Run Code Online (Sandbox Code Playgroud)

Yja*_*jay 9

务必.show()在祝酒后打电话.

boton_continuar.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        //Verificamos que se halla clikeado y se halla ingresado
        if(check.isChecked() && numero_celular.getText().length() != 0){
            Intent intent = new Intent(RegisterActivity.this, PrincipalActivity.class);
            startActivity(intent);
        } else {
            Context contexto = getApplicationContext();
            if(!check.isChecked()){                 
                Toast.makeText(contexto, "Debe aceptar los términos", 2000).show();
            }
            if(numero_celular.getText().length() == 0){
                Toast.makeText(contexto, "Debe ingresar su número", 2000).show();
            }
        }
    }});
Run Code Online (Sandbox Code Playgroud)

  • 另请注意,"2000"不是`makeText(...)`的有效第二个参数 (2认同)