0

I've got this dialog (I'm simplifying my use case):

class EditShoppingListDialog extends AlertDialog {

    public EditShoppingListDialog(Context context) {
        super(context/*, R.style.AppCustomDialog*/);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_addshoppinglist);
        setTitle("Mike Testing");
    }
}

I create and use this subclassed AlertDialog outside of the OnCreateDialog method (in the onContextItemSelected of my Activity) like this:

AlertDialog dialog = new EditShoppingListDialog(this);
dialog.show();

Now, I've been working with this code base for over a month now and never saw any problems, which lead me to wonder why they recommend using AlertDialog.Builder for creating custom dialogs also.

When I deployed my app to a real device, I immediately started to see problems. The most blocking of them is that I cannot get the soft keyboard (IME?) to show up even when I click on an EditText field in the AlertDialog.

Here's the best part; If I say:

class EditShoppingListDialog extends Dialog {
    ...
}

The IME appears appears automatically if I click in an EditText in the dialog. I found this thread but the accepted solution does not work with AlertDialog.

However, I found doing this on the OnCreate of my derived AlertDialog helps show the IME, but it goes behind the dialog and I can't interact with it:

InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,0);

I'm really sorry for the lost post, but I've spent more than 5 hours on this and would be very grateful for some help. The reason I insist on extending an AlertDialog is because I need a dialog without a title bar and it says in the Android Dialog documentation that I cannot have a Dialog without a title bar.

Community
  • 1
  • 1
Code Poet
  • 11,227
  • 19
  • 64
  • 97

2 Answers2

2

It is easy to set a dialog without title. create a style as below,

 <style name="no_title_dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>

initial dialog with

Dialog notitleDialog = new Dialog(this, R.style.no_title_dialog);

the dialog should appear with no title

AK5T
  • 114
  • 3
  • 3
    I feel like shooting myself in the mouth! This is straight forward enough for me to not have spent so many hours trying to figure out why AlertDialog wasn't working. I probably got blind sighted by reading this line in the android documentation - `A dialog made with the base Dialog class must have a title. If you don't call setTitle(), then the space used for the title remains empty, but still visible. If you don't want a title at all, then you should create your custom dialog using the AlertDialog class`. Thanks a gazillion. – Code Poet Dec 09 '11 at 17:20
0

Having an AlertDialog without a title bar is not magic at all:

AlertDialog.Builder builder;
AlertDialog alertDialog;

TextView v = new TextView(this);
v.setText("Should have no Bar...");

builder = new AlertDialog.Builder(this);
builder.setView(v);
alertDialog = builder.create();

alertDialog.show();

This looks like this:

no title bar

(No, this is not a Toast!). If this is not what you wanted, you should be more explicit on what you mean by "I need a dialog without a title bar".

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111