1

I have a form which opens a dialog box(which includes listview and a button) and if button is clicked, dialog should disappear and keyboard should be shown on form

I cant do it.Any idea?

Thanks for help!

My code is:

final Dialog dialog = new Dialog(context);
                 dialog.setContentView(R.layout.dialog_list_layout);
                 dialog.setCancelable(true);

                 final ListView listviewDialog = (ListView) dialog.findViewById(R.id.listViewDialog);
                 DialogListAdapter adapter = new DialogListAdapter(context, R.id.textViewItem, List);
                 listviewDialog.setAdapter(adapter);

        ((Button) dialog.findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {

                            public void onClick(View v) {                   
                                editText.setText("");


                                dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                                ((EditText) findViewById(R.id.editText)).requestFocus();
                                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                imm.showSoftInput(((EditText) findViewById(R.id.editTextAddress)), InputMethodManager.SHOW_IMPLICIT);

                                dialog.dismiss();       
                            }
                        });
                         dialog.show();
Android
  • 3,828
  • 9
  • 46
  • 79
rizaozdulger
  • 205
  • 2
  • 7

1 Answers1

1

Simply create one dialog, and on click of its button write your code for inputmanager

 AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(str1);
            builder.setCancelable(false);
            builder.setTitle("Status");
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) 
                 {

                    dialog.dismiss();
                   InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                   imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

                }
            });
            AlertDialog alert = builder.create();
            alert.show();

see my updated answer

Update

Apart from my answer see this is it possible to create listview inside dialog? and ListView in AlertDialog

Community
  • 1
  • 1
Android
  • 3,828
  • 9
  • 46
  • 79
  • No! i have also a dialog which includes button and listview.But problem is when i clicked button dialog dismiss but keyboard is not showing.my problem is keyboard is not showing! – rizaozdulger Jul 26 '12 at 12:03
  • try this `this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);` – Android Jul 26 '12 at 12:13