更改文本时启用和禁用按钮

时间:2016-07-22 08:19:19

标签: android

我正在构建一个walk应用程序,用户可以在其中设置目标。我想当用户输入超过阈值的目标时,开始按钮应该禁用,并且一旦他改变目标,按钮应该启用。 我试过但是即使我改变了目标,按钮也被设置为禁用。这是我的代码。

if (!empty($_POST) && !empty($_POST['pseudo']) && !empty($_POST['pass'])) {
require 'dbconnection.php';
require 'functions.php';
$req = $pdo->prepare('SELECT * FROM utilisateurs WHERE (login = :pseudo) AND activated != NULL');
$req->execute(['login' => $_POST['pseudo']]);
$user = $req->fetch();

if (password_verify($_POST['pass'], $user->password)) {
  session_start();
  $_SESSION['auth'] = $user;
  header('Location: index.php');
  exit();
}else{
  $_SESSION['flash']['danger'] = 'Login ou mot de passe incorrecte';
}

任何人都可以告诉我如何使其正确。

2 个答案:

答案 0 :(得分:0)

    if (arg0.length() > 0) {
                    // add toast message
                    if (targetType.equals(ParamConstants.FREE_WALK_TIMEBASEDWALK)) {
                        if (Integer.parseInt(getTargetString()) > 120) {
                            // startFreeWalk();
                            Toast.makeText(getActivity(), "Please enter a target between 1 and 120 minutes", Toast.LENGTH_LONG).show();
                        }else{
                             free_walk_start_btn.setClickable(true);//ENABLE 
BUTTON BACK
    free_walk_start_btn.setEnable(true);
                    }
                    else{
                        if(Integer.parseInt(getTargetString()) > 30 ) {
                            Toast.makeText(getActivity(), "Please enter a target between 1 and 30 kilometers", Toast.LENGTH_LONG).show();
                            free_walk_start_btn.setClickable(false);
                            free_walk_start_btn.setBackgroundColor(Color.parseColor("#808080"));
                        }

                    }
                    mSeekArkfreeWalk.setProgress(Integer.parseInt("" + arg0));
                    mSeekArkfreeWalkDistance.setProgress(Integer.parseInt("" + arg0));
                }

答案 1 :(得分:0)

  free_walk_elapsed_time_distance.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            if (!s.toString().trim().equals("")) {
             //write your code

              myButton.setEnabled(false); 
            } else {

            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            myButton.setEnabled(true); 
        }
    });