title: How to use AlertDialog to prompt for PIN
body: <p>So, I've researched quite a bit to try and implement a simple PIN authentication system for a Hello World game application. Unfortunately, I think a few things are still going over my head.</p>
  
  <p>As my code currently stands, it shows the dialog box and does not allow it to be canceled. However, the EditText field no longer appears, which defeats the purpose of asking for a PIN. I think that a linked XML file will be needed for layout purposes, however, Android Studio does not seem to accept a call to such a file (i.e. <code>pinauth.setView(findViewById(R.layout.dialog_pin));</code>, which I don't think is the correct structure anyway.</p>
  
  <p>Any assistance you can provide would be greatly appreciated. The code for the entire method is posted below.</p>
  
  <hr>
  
  <pre><code>public void auth(View v)
  {
  
  // The logout method works fine, since no PIN is necessary.
  if(users.getBoolean("activeLogin", false) == true) successLogout();
      else
      {
          // Get selected user and pull SharedPreferences to get stored PIN.
          final String activeUser = userList.getSelectedItem().toString();
          scores = getSharedPreferences(activeUser, 0);
  
          // If a PIN is found on file, launch AlertDialog to prompt for PIN. No XML file is linked to the AlertDialog at this time.
          if(scores.getInt("pin", 123456789) != 123456789)
          {
              AlertDialog.Builder pinAuth = new AlertDialog.Builder(this);
              pinAuth.setTitle("PIN required.");
              pinAuth.setMessage("Please enter your pin.");
              pinAuth.setCancelable(false);
              pinAuth.setView(findViewById(R.layout.dialog_pin))
              final EditText pin = new EditText(this);
              pin.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
  
              // These checks seem to work ok.
              pinAuth.setPositiveButton("Login", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      if(pin.getText().toString().isEmpty())
                      {
                          makeToast("Sorry, no pin was entered.", Toast.LENGTH_SHORT);
                          return;
                      }
                      else if(Integer.valueOf(pin.getText().toString()) != scores.getInt("pin", 123456789))
                      {
                          makeToast("Sorry, that pin was incorrect. Try again.", Toast.LENGTH_SHORT);
                          return;
                      }
                      else
                          successLogin(activeUser);
  
                  }
              });
  
              // Show the AlertDialog.
              pinAuth.show();
          }
  
          // if the account has no PIN
          else successLogin(activeUser);
      }
  }
  </code></pre>
  
  <p><em>As a side note, the PIN can only be up to 8 numeric characters, so <code>123456789</code> is an impossible PIN to create in the first place and therefore the conditional statement checking for the pin not to be equal to said number should not interfere with the operation.</em></p>