1

考虑到以下条件,当您单击“boton_continuar”按钮时,我试图显示祝酒词:EditExt Vacuum (numero_celular) 和 ckeckbox (check) 检查否。这是我的代码

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);
            }
    }
}});
4

5 回答 5

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();
            }
        }
    }});
于 2014-01-06T22:07:57.150 回答
3

两件事情:

  1. .show()上你做的吐司。
  2. 2000不是 Toast 的有效参数。这不会让它显示 2000 毫秒。Toast 接受的唯一参数是Toast.LENGTH_SHORTToast.LENGTH_LONG

所以:

更改这些行:

Toast.makeText(contexto, "Debe aceptar los términos", 2000);
Toast.makeText(contexto, "Debe ingresar su número", 2000);

到这些行:

Toast.makeText(contexto, "Debe aceptar los términos", Toast.LENGTH_SHORT).show();
Toast.makeText(contexto, "Debe ingresar su número", Toast.LENGTH_SHORT).show();

Toast.LENGTH_SHORT为 2000 毫秒(2 秒)和Toast.LENGTH_LONG3500 毫秒(3.5 秒)。

  • Toast.LENGTH_SHORT == 0所以你可以通过 is0代替。
  • Toast.LENGTH_LONG == 1所以你可以通过它1

Toast有关详细信息,请访问 Android 的文档。

于 2014-01-06T22:12:16.477 回答
1

您必须使用 SHOW 功能。

做:

Toast.makeText(contexto, "Debe ingresar su número", 2000).show();
于 2014-01-06T22:08:35.003 回答
1

您需要在“Toast.makeText()”之后添加“.show()”。

例如:

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();
            }
于 2014-01-06T22:11:57.633 回答
0

尝试以下操作:

 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();
            }


        }

    }});

您需要调用.show()Toast 以使其出现。

于 2014-01-06T22:08:10.933 回答