2016-12-07 1 views
0
showPasswordDialog(context); 
mFoundPassword = true; 
return errorcode; 

Приведенные выше два предложения в моем коде, и showPasswordDialog имеет слушателяКак может я выполнить следующее предложение до последнего (включая слушателя) сделано в Android

editText.setOnEditorActionListener(
      new TextView.OnEditorActionListener() { 
       @Override 
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 

        if (actionId == EditorInfo.IME_ACTION_DONE) { 

         String passwordInput = editText.getText().toString(); 

         int ndkErrorCode = mPdfRenderer.openDocument(mFileDescriptor, passwordInput); 
         if (ndkErrorCode == 0) { 
          Log.i(sClassTag, "Password is right!"); 
          mPassword = passwordInput; 

           mTag = true; 

          return true; 
         } else { 
          Log.e(sClassTag, "Password is wrong!"); 
          editText.setText(""); 
          } 

Я хочу, чтобы, когда пароль будет правильным, тогда код перейдет к выполнению mFoundPassword = true; или он будет блокировать ожидания ввода правильного пароля.

Любая помощь приветствуется.

ответ

0

Просто сделай это:

editText.setOnEditorActionListener(
      new TextView.OnEditorActionListener() { 
       @Override 
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 

        if (actionId == EditorInfo.IME_ACTION_DONE) { 

         String passwordInput = editText.getText().toString(); 

         int ndkErrorCode = mPdfRenderer.openDocument(mFileDescriptor, passwordInput); 
         if (ndkErrorCode == 0) { 
          Log.i(sClassTag, "Password is right!"); 
          mPassword = passwordInput; 
          //// Added code here 
          mFoundPassword = true; 
           mTag = true; 

          return true; 
         } else { 
          Log.e(sClassTag, "Password is wrong!"); 
          editText.setText(""); 
          } 
+0

если добавить код в слушатель действия он должен быть окончательным, и мне нужно выполнить код возврата после mFoundPassword = истина; –

+0

Не создавайте 'mFoundPassword' локальную переменную. –

+0

Я вижу, что ваш смысл, если он не является локальным, не может быть окончательным, но мне все равно нужно выполнить возвращаемое предложение ниже mFoundPassword, поэтому мне нужно идти в нужное место. –