Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

In this page you can find the example usage for android.app AlertDialog dismiss.

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:com.jereksel.rommanager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.

    switch (item.getItemId()) {
    case R.id.delete_xml:

        new Thread() {
            public void run() {

                runOnUiThread(new Runnable() {
                    @Override//from   w w w  .  j  a va2  s  . c om
                    public void run() {
                        Dialog = ProgressDialog.show(context, "Downloading/Preparing Data..", "Please wait",
                                true, false);
                    }
                });

                DownloadXML array;

                array = new DownloadXML(context, true);
                (array).start();

                try {
                    array.join();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Dialog.dismiss();
                        Intent mStartActivity = new Intent(context, MainActivity.class);
                        int mPendingIntentId = 123456;
                        PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId,
                                mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
                        AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
                        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
                        System.exit(0);

                    }
                });

            }
        }.start();
        break;

    case R.id.about_screen:
        Intent in = new Intent(context, AboutScreen.class);
        startActivity(in);
        break;

    case R.id.changelog_dialog:
        Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getString(R.string.AppChangelog));
        builder.setCancelable(true);
        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    }

    return mDrawerToggle.onOptionsItemSelected(item);

}

From source file:com.LMO.capstone.KnoWITHerbalMain.java

private void resolver() throws XmlPullParserException, IOException {
    if (!new File(Config.dbPath(getApplicationContext())).exists()) { //no DB, no Folder
        HowToUseFragment howto = new HowToUseFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.frame_content, howto);
        ft.addToBackStack("help");
        ft.commit();//from  w w  w . ja v  a2s .  co  m
        if (util.isNetworkAvailable())
            util.PrepareFileForDatabase();
    } else {
        File appDir = new File(Config.externalDirectory);
        if (!appDir.exists())
            appDir.mkdir();

        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                // TODO Auto-generated method stub
                return pathname.toString().toLowerCase(Locale.getDefault()).contains(".jpg")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".png")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".bmp")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".gif")
                        || pathname.toString().toLowerCase(Locale.getDefault()).contains(".jpeg");
            }
        };
        File[] files = appDir.listFiles(filter);
        dbHelper = new DatabaseHelper(this);
        int imageEntryCount = Queries.getImageEntryCount(sqliteDB, dbHelper);

        if (files.length == 1 || (files.length + 1) < imageEntryCount) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            AlertDialog dialog = builder.create();
            dialog.setTitle("Oops!");
            dialog.setMessage("It seems your data is invalid!\nRe-download now?");
            dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    if (util.isNetworkAvailable())
                        Queries.truncateDatabase(sqliteDB, dbHelper, getApplicationContext());
                    util.PrepareFileForDatabase();
                }
            });
            dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Maybe later", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();
                }
            });
            dialog.show();
        }
    }
}

From source file:com.example.spencerdepas.translationapp.activities.DMVStudyActivity.java

private void showSelectQuestionDialog() {
    Log.d(TAG, "showAlertDialog");
    // Prepare grid view
    GridView gridView = new GridView(this);

    int questionSize = driverQuestions.getQuestions().size();
    List<Integer> mList = new ArrayList<Integer>();
    for (int i = 1; i < questionSize + 1; i++) {
        mList.add(i);//from  w  ww  .j  a v  a 2  s . c om
    }

    gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);

            boolean hasBeenAnswered = hasBeenAnswered(position);
            Log.d(TAG, "hasBeenAnswered : " + hasBeenAnswered);
            int color = 0x00FFFFFF; // Transparent
            if (hasBeenAnswered) {

                if (driverQuestions.getQuestions().get(position).isAnsweredCorrectly()) {
                    //answer is correct
                    view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid));
                } else {
                    //answer is incorrect
                    view.setBackgroundColor(getResources().getColor(R.color.red));
                }

            } else {

                view.setBackgroundColor(color);
            }

            return view;
        }
    });
    gridView.setNumColumns(4);

    // Set grid view to alertDialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(gridView);
    builder.setTitle(getResources().getString(R.string.select_question));
    builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(TAG, getResources().getString(R.string.dialog_dismiss));
                    dialog.dismiss();
                }
            });

    final AlertDialog ad = builder.show();

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // do something here
            Log.d(TAG, "onclick");

            if (position == 0) {
                makePrevousButtonUnclickable();
            } else {
                makePrevousButtonClickable();
            }

            mNextButton.setText(getResources().getString(R.string.next_button));
            Log.d(TAG, "int pos : " + position);
            if (position == 193) {
                mNextButton.setText(getResources().getString(R.string.finish_studying));
            }

            goToSelectedQuestion(position);
            ad.dismiss();
        }
    });

}

From source file:com.bti360.hackathon.listview.HackathonActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case ADD_DIALOG:
        // We are going to create an AlertDialog with a single text input and a button
        // first we create the EditText
        final EditText edit = new EditText(this);
        // Next we create an AlertDialog.Builder which creates a styled AlertDialog based
        // on our specifications;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // set the title
        builder.setTitle("Add Person");
        // set the icon to a built-in, this one is a +
        builder.setIcon(android.R.drawable.ic_input_add);
        // set the text of the only button, and add a click listener
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            @Override/*from w w  w. j  a v a 2 s .com*/
            public void onClick(DialogInterface dialog, int which) {
                // on the Ok Button we grab the text from the EditText,
                // clear it and then add the Name to our list
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
            }
        });
        // finally let's create the dialog
        final AlertDialog d = builder.create();
        // and set the view to our EditText
        d.setView(edit);

        // we'll set a special InputType since we are collecting a name
        // other's exist such as email, address, phone number, etc
        // this allows the IME (keyboard) to customize itself based on
        // expected input, e.g. show @ and .com when Email
        edit.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
        // Respond to the default action on the IME (keyboard) By default it is
        // "Done" but it can be changed with setImeActionLabel to be something
        // else like a search hourglass.
        // In our case we want a click on "Done" to do the same thing as a click
        // on the Ok button in the Dialog.
        edit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView tv, int actionId, KeyEvent arg2) {
                // same as the DialogClick Handler except we also dismiss the dialog
                String name = edit.getText().toString();
                edit.setText("");
                addName(name);
                d.dismiss();
                return true;
            }
        });
        return d;
    }
    return super.onCreateDialog(id);
}

From source file:org.thbz.hanguldrill.ConfigManageDialogFragment.java

@Override
public void onStart() {
    super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point
    final AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {
        Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override//from  w  w  w .j av  a2 s. c o m
            public void onClick(View v) {
                // Only dismiss the dialog if the user confirms the deletion
                int nbToDelete = configsSelected.size();
                if (nbToDelete == 0) {
                    alert("You have selected no configuration.");
                } else {
                    // Confirm
                    String message = "Do you really want to delete " + nbToDelete + " configuration"
                            + (nbToDelete >= 2 ? "s" : "") + "?";
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    AlertDialog dialog = builder.setMessage(message)
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // Save the configurations and dismiss the dialog
                                    mListener.onConfigManageSaveClick(configsSelected);
                                    d.dismiss();
                                }
                            }).setNegativeButton("No", null).create();
                    dialog.show();
                }
            }
        });
    }
}

From source file:com.learnncode.mediachooser.activity.HomeScreenMediaChooser.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == MediaChooserConstants.BUCKET_SELECT_IMAGE_CODE) {
            addMedia(mSelectedImage, data.getStringArrayListExtra("list"));

        } else if (requestCode == MediaChooserConstants.BUCKET_SELECT_VIDEO_CODE) {
            addMedia(mSelectedVideo, data.getStringArrayListExtra("list"));

        } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));
            final AlertDialog alertDialog = MediaChooserConstants.getDialog(mContext).create();
            alertDialog.show();/*  www  . j  av  a  2 s.c o  m*/

            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Do something after 2000ms
                    String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim();
                    Fragment fragment = mViewPagerAdapter.getItem(0);

                    if (fragment instanceof ImageFragment) {
                        ImageFragment imageFragment = (ImageFragment) fragment;

                        if (imageFragment != null) {
                            imageFragment.addNewEntry(fileUriString);
                        }
                    } else {

                        ImageFragment imageFragment = (ImageFragment) mViewPagerAdapter.getItem(1);

                        if (imageFragment != null) {
                            imageFragment.addNewEntry(fileUriString);
                        }
                    }

                    alertDialog.dismiss();
                }
            }, 5000);

        } else if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {

            sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));

            final AlertDialog alertDialog = MediaChooserConstants.getDialog(mContext).create();
            alertDialog.show();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    //Do something after 2000ms
                    String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim();

                    Fragment fragment = mViewPagerAdapter.getItem(0);
                    if (fragment instanceof VideoFragment) {
                        VideoFragment videoFragment = (VideoFragment) fragment;

                        if (videoFragment != null) {
                            videoFragment.addNewEntry(fileUriString);
                        }
                    } else {

                        VideoFragment videoFragment = (VideoFragment) mViewPagerAdapter.getItem(1);

                        if (videoFragment != null) {
                            videoFragment.addNewEntry(fileUriString);
                        }
                    }
                    alertDialog.dismiss();
                }
            }, 5000);
        }
    }
}

From source file:foam.littlej.android.app.ui.phone.AddReportActivity.java

/**
 * Create various dialog// w  w w. java 2s. c  o m
 */
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ERROR_NETWORK: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.network_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }
    case DIALOG_ERROR_SAVING: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.network_error));
        dialog.setMessage(getString(R.string.file_system_error_msg));
        dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_CHOOSE_IMAGE_METHOD: {

        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.choose_method));
        dialog.setMessage(getString(R.string.how_to_select_pic));
        dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, REQUEST_CODE_IMAGE);
                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT,
                        PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
                startActivityForResult(intent, REQUEST_CODE_CAMERA);
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    case DIALOG_MULTIPLE_CATEGORY: {
        if (showCategories() != null) {
            return new AlertDialog.Builder(this).setTitle(R.string.choose_categories)
                    .setMultiChoiceItems(showCategories(), setCheckedCategories(),
                            new DialogInterface.OnMultiChoiceClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton,
                                        boolean isChecked) {
                                    // see if categories have previously

                                    if (isChecked) {
                                        mVectorCategories.add(mCategoriesId.get(whichButton));

                                        mError = false;
                                    } else {
                                        mVectorCategories.remove(mCategoriesId.get(whichButton));
                                    }

                                    setSelectedCategories(mVectorCategories);
                                }
                            })
                    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {

                            /* User clicked Yes so do some stuff */
                        }
                    }).create();
        }
    }

    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR),
                mCalendar.get(Calendar.MINUTE), false);

    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR),
                mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));

    case DIALOG_SHOW_MESSAGE:
        AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
        messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showDialog = messageBuilder.create();
        showDialog.show();
        break;

    case DIALOG_SHOW_REQUIRED:
        AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
        requiredBuilder.setTitle(R.string.required_fields);
        requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

        AlertDialog showRequiredDialog = requiredBuilder.create();
        showRequiredDialog.show();
        break;

    // prompt for unsaved changes
    case DIALOG_SHOW_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.unsaved_changes));
        dialog.setMessage(getString(R.string.want_to_cancel));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                new DiscardTask(AddReportActivity.this).execute((String) null);
                finish();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    // prompt for report deletion
    case DIALOG_SHOW_DELETE_PROMPT: {
        AlertDialog dialog = (new AlertDialog.Builder(this)).create();
        dialog.setTitle(getString(R.string.delete_report));
        dialog.setMessage(getString(R.string.want_to_delete));
        dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // delete report
                deleteReport();
                dialog.dismiss();
            }
        });

        dialog.setCancelable(false);
        return dialog;
    }

    }
    return null;
}

From source file:com.morlunk.mumbleclient.servers.PublicServerListFragment.java

private void showFilterDialog() {
    View dialogView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.dialog_server_search, null);
    final EditText nameText = (EditText) dialogView.findViewById(R.id.server_search_name);
    final EditText countryText = (EditText) dialogView.findViewById(R.id.server_search_country);

    final AlertDialog dlg = new AlertDialog.Builder(getActivity()).setTitle(R.string.search).setView(dialogView)
            .setPositiveButton(R.string.search, new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int which) {
                    String queryName = nameText.getText().toString().toUpperCase(Locale.US);
                    String queryCountry = countryText.getText().toString().toUpperCase(Locale.US);
                    mServerAdapter.filter(queryName, queryCountry);
                    dialog.dismiss();//from ww  w.ja va  2 s  .  c  o  m
                }
            }).create();

    nameText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    nameText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            String queryName = nameText.getText().toString().toUpperCase(Locale.US);
            String queryCountry = countryText.getText().toString().toUpperCase(Locale.US);
            mServerAdapter.filter(queryName, queryCountry);
            dlg.dismiss();
            return true;
        }
    });

    countryText.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    countryText.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            String queryName = nameText.getText().toString().toUpperCase(Locale.US);
            String queryCountry = countryText.getText().toString().toUpperCase(Locale.US);
            mServerAdapter.filter(queryName, queryCountry);
            dlg.dismiss();
            return true;
        }
    });

    // Show keyboard automatically
    nameText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                dlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    dlg.show();
}

From source file:com.example.spencerdepas.translationapp.activities.DMVSimulationActivity.java

private void showSelectQuestionDialog() {
    Log.d(TAG, "showAlertDialog");
    // Prepare grid view
    GridView gridView = new GridView(this);

    List<Integer> mList = new ArrayList<Integer>();
    for (int i = 1; i < 21; i++) {
        mList.add(i);/*from  w  ww.  j  a  v a 2s. com*/
    }

    // gridView.setAdapter(new ArrayAdapter<>(this, R.layout.custom_list_item, mList));
    gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);

            boolean hasBeenAnswered = hasBeenAnswered(position);

            int color = 0x00FFFFFF; // Transparent
            if (hasBeenAnswered) {
                view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid));
            } else {

                view.setBackgroundColor(color);
            }

            return view;
        }
    });

    gridView.setNumColumns(4);

    // Set grid view to alertDialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(gridView);
    builder.setTitle(getResources().getString(R.string.select_question));
    builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(TAG, "DISMISS");
                    dialog.dismiss();
                }
            });

    final AlertDialog ad = builder.show();

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // do something here
            Log.d(TAG, "onclick");

            saveAnswer();
            unSelectRadioButtons();

            loadRadioButtonSelection();

            if (position == 0) {
                makePrevousButtonUnclickable();
            } else {
                makePrevousButtonClickable();
            }
            mNextButton.setText(getResources().getString(R.string.next_button));
            Log.d(TAG, "int pos : " + position);
            goToSelectedQuestion(position);
            ad.dismiss();
        }
    });

}

From source file:fr.forexperts.ui.ArticleListFragment.java

public void showAddDialog() {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View alertView = inflater.inflate(R.layout.alertdialog_add_value, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(alertView);/*  w w w  . j  av  a 2  s .  c  om*/
    final AlertDialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
    wmlp.gravity = Gravity.TOP | Gravity.CENTER;
    wmlp.x = 10;
    wmlp.y = 10;

    final EditText mStockName = (EditText) alertView.findViewById(R.id.stockName);
    mListViewStock = (ListView) alertView.findViewById(R.id.listViewStock);
    mListViewStock.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String text = (String) parent.getItemAtPosition(position);
            String[] result = text.split(" ");
            Intent detailIntent = new Intent(getActivity(), GraphActivity.class);
            detailIntent.putExtra("code", result[0]);
            startActivity(detailIntent);
            dialog.dismiss();
        }
    });

    mStockName.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            SuggestStockTask task = new SuggestStockTask();
            task.execute(mStockName.getText().toString());
        }
    });

    // TODO: Change hard coded width
    mStockName.setWidth(10000);

    dialog.show();
}