gpt4 book ai didi

android - 为什么在android中按下按钮不激活 toast ?

转载 作者:行者123 更新时间:2023-11-29 14:19:52 25 4
gpt4 key购买 nike

在满足以下条件的情况下,当您单击“boton_continuar”按钮时,我正在尝试显示 toast :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);
}
}
}});

最佳答案

确保在 toast 后调用 .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();
}
}
}});

关于android - 为什么在android中按下按钮不激活 toast ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20960190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com