title: Android: using spinning wheel progress dialog not working properly
body: <p>I am designing a login screen and want to display a spinning wheel with "Please Wait..." text when clicked on Login button. If the username and password matches then next screen should be displayed else an error message should be displayed. My problem is that when the button is pressed process dialog is coming but next screen or the error message is not displayed after closing the dialog. I am having the following code. Please help me where i am doing wrong.</p>
  
  <pre><code>  package com.example.first_db_app;
  
    import java.util.List;
  
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
  
   public class TestDbActivity extends Activity
   {
  
  
  
  
  @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_test_db);
  
  
          DatabaseHandler db=new DatabaseHandler(this);
  
  
          //CRUD operations
  
          //inserting the records
          /*Log.d("Insert: ", "Inserting ..");
          db.addUser(new User("Ashwin","11111"));
          db.addUser(new User("Ravi","22222"));
          db.addUser(new User("Gopal","33333"));
          db.addUser(new User("Satish","44444"));*/
  
  
           // Reading all contacts
          Log.d("Reading: ", "Reading all contacts..");
          List&lt;User&gt; user = db.getAllContacts();       
  
          for (User us : user) {
              String log = "Name: " + us.getUname()  + " ,Password " + us.getUpwd();
                  // Writing Contacts to log
          Log.d("Name: ", log);
          }
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) 
      {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.test_db, menu);
          return true;
      }
  
      public void login(View v)
      {
          final  EditText edtuname=(EditText) findViewById(R.id.editTextUserNameToLogin);
          final  EditText edtpwd=(EditText) findViewById(R.id.editTextPasswordToLogin);
            Button btnlogin=(Button) findViewById(R.id.buttonSignIn);
           final DatabaseHandler db=new DatabaseHandler(this);
  
            btnlogin.setOnClickListener(new View.OnClickListener()
            {
  
              @Override
              public void onClick(View v) 
              {
                  // TODO Auto-generated method stub
  
                  final ProgressDialog mypd=ProgressDialog.show(TestDbActivity.this, "", "Loading..",true);
                  new Thread (new Runnable()
                  {
                      @Override
                      public void run()
                      {
                          try
                          {
  
                              String uname= edtuname.getText().toString();
                              String pwd=edtpwd.getText().toString();
                              String stored_pwd=db.getUser(uname);
                              Thread.sleep(5000);
  
                              if(pwd.equals(stored_pwd))
                              {
  
  
  
                                  //Toast.makeText(TestDbActivity.this,"successful", Toast.LENGTH_LONG).show();
                                  mypd.dismiss();
                                  setContentView(R.layout.activity_next);
                              }
                              else
                              {
                                  mypd.dismiss();
                                  Toast.makeText(TestDbActivity.this, "failed", Toast.LENGTH_LONG).show();
  
                              }
                          }
                          catch (Exception e)
                          {
  
                          }
  
  
                      }
  
                  }).start();
  
  
  
  
  
              }
          } );
  
      }
  
  
  }
  
  
  Thanks in advance.
  </code></pre>