title: How to set up a Login Dialog in Android?
body: <p>I was trying to add a login in my edit button. What I want to do is that, when a user selected an item to edit, then hits the edit button a pop-up will show asking for the person's username and password. I tried making a login dialog but I keep on failing.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void btn_edit_click(View v){
          LayoutInflater li = LayoutInflater.from(context);
          View prompt = li.inflate(R.layout.prompts, null);
          AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
          alertDialogBuilder.setView(prompt);
          final String username = getIntent().getStringExtra("USERNAME");
          final EditText user = (EditText) prompt.findViewById(R.id.loginEmail);
          final EditText pass = (EditText) prompt.findViewById(R.id.loginPassword);
          final TextView msg = (TextView) prompt.findViewById(R.id.login_error);
          final String password = pass.getText().toString();
          user.setText(getIntent().getStringExtra("USERNAME"));
          if(this.selected_website != null){
              alertDialogBuilder.setCancelable(false)
              .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int id) {   
                      DBAdapter dbUser = new DBAdapter(PasswordActivity.this);
                      dbUser.open();
                      if(dbUser.Login(username, password))
                      {
                          show_add_layout();
  
                      }
                      else
                      {
                          msg.setText("Username or Password is incorrect");
                      }
                  }
                  });
  
                      alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialog, int id) {
                              dialog.cancel();
  
                          }
                      });
                      alertDialogBuilder.show();  
                      }                   
                      else{
                          show_mesg("Please select item to edit.");
                      }
      }
  </code></pre>
  
  <p>When I click the OK button, it gives me the statement "Username or Password is incorrect". But I have typed the right username and password. Any help on this? </p>