Progress dialog unnecessary showing
<p>Hi i made an activity like </p>

<pre><code>....
&lt;TableRow &gt;
    &lt;TextView
        android:text="@string/userName"
        android:width ="100dp" /&gt;

    &lt;EditText
        android:id="@+id/txt_userName"
        android:width="100dp"
        android:hint="@string/userName" /&gt;
&lt;/TableRow&gt;

&lt;TableRow&gt;
    &lt;TextView
        android:text="@string/password" /&gt;

    &lt;EditText
        android:id="@+id/txt_password"
        android:inputType="textPassword"
        android:hint="@string/password" /&gt;
&lt;/TableRow&gt;
    ....
</code></pre>

<p>here is my class</p>

<pre><code>public class LoginActivity extends Activity {
    private boolean rememberpassword = false;
    ProgressDialog dialog = null;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);

        Button btn_logIn = (Button)findViewById(R.id.btn_signIn );
        btn_logIn.setOnClickListener(new OnClickListener() {            
            @Override
            public void onClick(View view) {
                showProgressDialog();
                getUserCredentials();           
            }           
        }); //end of anonymous class
    } //end of onCreate

    private void showProgressDialog() {

        dialog = new ProgressDialog(this);
        dialog.setMessage("Please Wait. Your authentication is in progress");
        dialog.setButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {                
                dialog.dismiss();               
            }
        }); //end of anonymous class    
    } //end of showProgressDialog()

    private void getUserCredentials() {

        EditText txt_userName = (EditText) findViewById(R.id.txt_userName);
        String userName = txt_userName.getText().toString();

        EditText txt_password = (EditText) findViewById(R.id.txt_password);
        String password = txt_password.getText().toString();

        if (userName != null &amp;&amp; !userName.trim().equals("") &amp;&amp; password != null &amp;&amp; !password.trim().equals("")) {           
            dialog.show();
            callWebServide(userName, password);         
        } else if (userName == null) {          
            Toast.makeText(this, "User Name is required", Toast.LENGTH_LONG).show();        
        } else if (password == null &amp;&amp; password.trim().equals("")) {        
            Toast.makeText(this, "Password is required", Toast.LENGTH_LONG).show();         
        }   
    } //end of getUserCredentials()

} //end of class LoginActivity
</code></pre>

<p>First my both conditions aren't working </p>

<pre><code>} else if (userName == null) {
    Toast.makeText(this, "User Name is required", Toast.LENGTH_LONG).show();        
} else if (password == null &amp;&amp; password.trim().equals("")) {
    Toast.makeText(this, "Password is required", Toast.LENGTH_LONG).show();         
}
</code></pre>

<p>Means when my activity launches then there is a hint in the editText, if i click on the login button then it should show toast that password or username is required. but it isn't :(. Second i used</p>

<pre><code>if (userName != null &amp;&amp; !userName.trim().equals("") &amp;&amp; password != null &amp;&amp; !password.trim().equals("")) {       
    dialog.show();
    callWebServide(userName, password);         
}
</code></pre>

<p>Means dialog should only be shown when userName and password must not be empty, but as soon as i click on login button then dialog start showing, only hints are in the editText. I didn't mention in my on click that <code>dialog.show()</code>. Although i am creating a dialog but aren't showing it.</p>

<p>why it is behaving unexpectedly? Am i doing anything wrong? </p>

<p>Thanks</p>
