LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.prompts, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Light_Dialog));
alertDialogBuilder.setView(promptsView);
final EditText mEditText=(EditText)promptsView.findViewById(R.id.editTextDialogUserInput);
alertDialogBuilder.setMessage("Test for preventing dialog close");
alertDialogBuilder.setPositiveButton("Test",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
final AlertDialog dialog = alertDialogBuilder.create();
dialog.show();
//Overriding the handler immediately after show is probably a better approach than OnShowListener as described below
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Boolean wantToCloseDialog = false;
if (mEditText.getText().toString().trim().equalsIgnoreCase("")) {
wantToCloseDialog=false;
Toast.makeText(getApplicationContext(), "Enter Desription", 2000).show();
}
else {
wantToCloseDialog=true;
}
if(wantToCloseDialog==true)
dialog.dismiss();
//else dialog stays open. Make sure you have an obvious way to close the dialog especially if you set cancellable to false.
}
});
View promptsView = li.inflate(R.layout.prompts, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(context, android.R.style.Theme_Holo_Light_Dialog));
alertDialogBuilder.setView(promptsView);
final EditText mEditText=(EditText)promptsView.findViewById(R.id.editTextDialogUserInput);
alertDialogBuilder.setMessage("Test for preventing dialog close");
alertDialogBuilder.setPositiveButton("Test",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
final AlertDialog dialog = alertDialogBuilder.create();
dialog.show();
//Overriding the handler immediately after show is probably a better approach than OnShowListener as described below
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Boolean wantToCloseDialog = false;
if (mEditText.getText().toString().trim().equalsIgnoreCase("")) {
wantToCloseDialog=false;
Toast.makeText(getApplicationContext(), "Enter Desription", 2000).show();
}
else {
wantToCloseDialog=true;
}
if(wantToCloseDialog==true)
dialog.dismiss();
//else dialog stays open. Make sure you have an obvious way to close the dialog especially if you set cancellable to false.
}
});
No comments:
Post a Comment