I have create one Alert Dialog which have two EditText and two Button and I fetch the value of the EditText and if value matches then I am doing some operation otherwise I want to call same AlertDialog again.But if value differs then I am not able to call the same alert dialog.I don't know where i am doing wrong... 
My Code goes like this ::
public class MainActivity extends Activity 
{
private Button btn_click;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn_click=(Button)findViewById(R.id.btn_click);
    btn_click.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View arg0) 
        {
            showDialog(0);
        }
    });
}
@Override
protected Dialog onCreateDialog(int id) 
{
    switch (id) 
    {
    case 0:
        // This example shows how to add a custom layout to an AlertDialog
        android.app.AlertDialog.Builder login = new android.app.AlertDialog.Builder(this);
        try
        {
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.login_dialog, null);
            final EditText username_alert = (EditText) textEntryView.findViewById(R.id.username);
            final EditText password_alert = (EditText) textEntryView.findViewById(R.id.password);
            login.setTitle("Login").setIcon(R.drawable.ic_launcher).setView(textEntryView)
            .setPositiveButton("Login", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int whichButton) 
                {
                    /* User clicked OK so do some stuff */
                    String uname_alert=username_alert.getText().toString();
                    String pass_alert=password_alert.getText().toString();
                    if(uname_alert.equals("aaaa") && pass_alert.equals("aaaa"))
                    {
                        //do Something........
                    }
                    else
                    {
                        showDialog(0);
                    }
                }
            })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int whichButton) 
                {
                    /* User clicked cancel so do some stuff */
                }
            });
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return login.create();
    }
    return null;
}
  }
Hope my question is clear....... Please help me .. Thanks in Advance ..... :)
 
     
     
     
     
    