Example usage for android.app AlertDialog.Builder AlertDialog.Builder

List of usage examples for android.app AlertDialog.Builder AlertDialog.Builder

Introduction

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

Prototype

public Builder(Context context) 

Source Link

Document

Creates a builder for an alert dialog that uses the default alert dialog theme.

Usage

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

public void showFollowDialog() {
    new AlertDialog.Builder(context).setItems(new CharSequence[] { "@TestAndroid", "@daiv", "'s Google+" },
            new DialogInterface.OnClickListener() {
                @Override//from  ww w  .  j a  v a  2s . c om
                public void onClick(DialogInterface dialogInterface, int i) {

                    if (i == 0) {
                    } else if (i == 1) {
                        // "" (twitter)
                    } else {
                        // "" (google+)
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/+daiv")));
                    }

                }
            }).create().show();
}

From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java

private void showContactUsDialog() {
    new AlertDialog.Builder(context).setItems(new CharSequence[] { "Twitter", "Google+", "Email" },
            new DialogInterface.OnClickListener() {
                @Override/*from w  w  w. j av  a2  s . co m*/
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        final Intent tweet = new Intent(context, ComposeActivity.class);
                        new AlertDialog.Builder(context)
                                .setItems(new CharSequence[] { "@TalonAndroid", "@lukeklinker" },
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                if (i == 0) {
                                                    tweet.putExtra("user", "@TalonAndroid");
                                                } else {
                                                    tweet.putExtra("user", "@lukeklinker");
                                                }
                                                startActivity(tweet);
                                            }
                                        })
                                .create().show();
                    } else if (i == 1) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://goo.gl/KCXlZk")));
                    } else {
                        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                                new String[] { "luke@klinkerapps.com" });
                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Talon (Classic)");
                        emailIntent.setType("plain/text");

                        startActivity(emailIntent);
                    }
                }
            }).create().show();
}

From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java

public void showFollowDialog() {
    new AlertDialog.Builder(context)
            .setItems(new CharSequence[] { "@TalonAndroid", "@lukeklinker", "Luke's Google+" },
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                            if (i == 0) {
                                // talon
                                Intent profile = new Intent(context, ProfilePager.class);
                                profile.putExtra("screenname", "TalonAndroid");
                                profile.putExtra("proPic", "");
                                startActivity(profile);
                            } else if (i == 1) {
                                // luke (twitter)
                                Intent profile = new Intent(context, ProfilePager.class);
                                profile.putExtra("screenname", "lukeklinker");
                                profile.putExtra("proPic", "");
                                startActivity(profile);
                            } else {
                                // luke (google+)
                                startActivity(new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("http://google.com/+LukeKlinker")));
                            }//from  w ww.  j  ava2  s. co  m

                        }
                    })
            .create().show();
}

From source file:com.free.searcher.MainFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("data", "" + data);
    Log.d("requestCode", "" + requestCode);
    Log.d("resultCode", "" + resultCode);
    locX = 0;//from w  w w  . j  a v  a2 s.  com
    locY = 0;
    try {
        if (data != null) {
            String[] stringExtra = data.getStringArrayExtra(FolderChooserActivity.SELECTED_DIR);
            if (requestCode == SEARCH_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    Log.d("SEARCH_REQUEST_CODE.selectedFiles",
                            Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP));
                    currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                    selectedFiles = stringExtra;
                    getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                    getSourceFileTask.execute();
                    load = "Search";
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to search");
                        statusView.setText("Nothing to search");
                    }
                }
            } else if (requestCode == ZIP_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    currentZipFileName = stringExtra[0];
                    selectedFiles = stringExtra;
                    load = "Zip Reader";
                    Log.d("ZIP_REQUEST_CODE.currentZFile", currentZipFileName);
                    statusView.setText("reading " + currentZipFileName + "...");
                    try {
                        zr = new ZipReadingTask(MainFragment.this);
                        zr.execute();
                    } catch (Exception e) {
                        statusView.setText(e.getMessage());
                        Log.d("zip result", e.getMessage(), e);
                        showToast(e.getMessage());
                    }
                } else if (currentZipFileName.length() == 0) {
                    showToast("Nothing to read");
                    statusView.setText("Nothing to read");
                }
                //            } else if (requestCode == COMPARE_REQUEST_CODE1) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  oriDoc = stringExtra[0];
                //                  Log.d("COMPARE_REQUEST_CODE1.oriDoc", oriDoc);
                //                  Intent intent = new Intent(activity, FolderChooserActivity.class);
                //                  intent.putExtra(MainFragment.SELECTED_DIR,
                //                              new String[] { oriDoc });
                //                  intent.putExtra(MainFragment.SUFFIX, DOC_FILES_SUFFIX);
                //                  intent.putExtra(MainFragment.MODE, !MULTI_FILES);
                //                  intent.putExtra(MainFragment.CHOOSER_TITLE,MODI_SUFFIX_TITLE);
                //                  activity.startActivityForResult(intent, COMPARE_REQUEST_CODE2);
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to compare");
                //                     statusView.setText("Nothing to compare");
                //                  }
                //               }
                //            } else if (requestCode == COMPARE_REQUEST_CODE2) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  stopReadAndSearch();
                //                  modifiedDoc = stringExtra[0];
                //                  Log.d("COMPARE_REQUEST_CODE2.modifiedDoc", modifiedDoc);
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  selectedFiles = new  String[] {oriDoc, modifiedDoc};
                //                  load = "Search";
                //                  requestCompare = true;
                //                  requestSearching = false;
                //                  getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                //                  getSourceFileTask.execute();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to compare");
                //                     statusView.setText("Nothing to compare");
                //                  }
                //               }
            } else if (requestCode == GEN_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("GEN_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    genStardictTask = new GenStardictTask(MainFragment.this, stringExtra[0]);
                    genStardictTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to generate");
                        statusView.setText("Nothing to generate");
                    }
                }
            } else if (requestCode == RESTORE_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("RESTORE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    restoreStardictTask = new RestoreStardictTask(MainFragment.this, stringExtra[0]);
                    restoreStardictTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to restore");
                        statusView.setText("Nothing to restore");
                    }
                }
            } else if (requestCode == DUP_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    Log.d("DUP_REQUEST_CODE.selectedFiles",
                            Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP));

                    if (FileUtils.treeUri == null) {// && !checkFolder(new File(st).getParentFile(), WRITE_REQUEST_CODE)) {
                        FileUtils.applicationContext = activity;
                        FileUtils.treeUri = FileUtils
                                .getSharedPreferenceUri(R.string.key_internal_uri_extsdcard);
                        if (FileUtils.treeUri == null) {
                            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                            alert.setTitle("Grant Permission in extSdCard");
                            alert.setMessage("In the following Android dialog, "
                                    + "please select the external SD card and confirm at the bottom.");
                            alert.setCancelable(true);
                            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    triggerStorageAccessFramework(INTENT_WRITE_REQUEST_CODE);
                                }
                            });
                            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                }
                            });
                            AlertDialog alertDialog = alert.create();
                            alertDialog.show();
                        }
                    }
                    dupTask = new DupFinderTask(MainFragment.this, stringExtra);
                    dupTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to find");
                        statusView.setText("Nothing to find");
                    }
                }
            } else if (requestCode == INTENT_WRITE_REQUEST_CODE) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    onActivityResultLollipop(requestCode, resultCode, data);
                }
            } else if (requestCode == TRANSLATE_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("TRANSLATE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    stopReadAndSearch();
                    currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                    selectedFiles = stringExtra;
                    load = "Search";
                    requestCompare = false;
                    requestTranslate = true;
                    requestSearching = false;
                    getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                    getSourceFileTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to translate");
                        statusView.setText("Nothing to translate");
                    }
                }
                //            } else if (requestCode == REPLACE_REQUEST_CODE) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  Log.d("REPLACE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                //                  stopReadAndSearch();
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  selectedFiles = stringExtra;
                //                  load = "Search";
                //                  requestCompare = false;
                //                  requestTranslate = false;
                //                  requestSearching = false;
                //                  List<File> lf = FileUtil.getFiles(selectedFiles);
                //                  if (includeEnter) { // multiline
                //                     new ReplaceAllTask(this, lf, isRegex, caseSensitive, new String[]{replace}, new String[]{by}).execute();
                //                  } else {
                //                     String[] replaces = replace.split("\r?\n");
                //                     String[] bys = by.split("\r?\n");
                //                     Log.d("bys.length ", bys.length + ".");
                //                     if (replaces.length == bys.length) {
                //                        new ReplaceAllTask(this, lf, isRegex, caseSensitive, replaces, bys).execute();
                //                     } else {
                //                        showToast("The number of lines of replace and by are not equal");
                //                     }
                //                  }
                //                  getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                //                  getSourceFileTask.execute();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to translate");
                //                     statusView.setText("Nothing to translate");
                //                  }
                //               }
                //            } else if (requestCode == BATCH_REQUEST_CODE_1) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  selectedFiles = stringExtra;
                //                  Log.d("BATCH_REQUEST_CODE_1.selectedFiles", Util.arrayToString(selectedFiles, true, "\n"));
                //                  Intent intent = new Intent(activity, FolderChooserActivity.class);
                //                  intent.putExtra(SearchFragment.SELECTED_DIR,
                //                              selectedFiles);
                //                  intent.putExtra(SearchFragment.SUFFIX, "");
                //                  intent.putExtra(SearchFragment.MODE, !MULTI_FILES);
                //                  intent.putExtra(SearchFragment.CHOOSER_TITLE, "Output Folder");
                //                  activity.startActivityForResult(intent, BATCH_REQUEST_CODE_2);
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to convert");
                //                     statusView.setText("Nothing to convert");
                //                  }
                //               }
                //            } else if (requestCode == BATCH_REQUEST_CODE_2) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  stopReadAndSearch();
                //                  outputFolder = stringExtra[0];
                //                  Log.d("BATCH_REQUEST_CODE_2.outputfolder", outputFolder);
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  load = "Convert";
                //                  
                //                  Log.i(Prefs.TAG, "onCreate ffmpeg4android ProgressBarExample");
                ////                  demoVideoFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/videokit/";
                //                  Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(activity.getApplicationContext()) );
                //                  workFolder = SearchFragment.PRIVATE_PATH + "/"; //activity.getApplicationContext().getFilesDir() + "/";
                //                  Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder);
                //                  vkLogPath = SearchFragment.PRIVATE_PATH + "/vk.log";
                //                  Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath);
                //                  GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(activity, workFolder);
                //                  //GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(activity, demoVideoFolder);
                //                  int rc = GeneralUtils.isLicenseValid(activity.getApplicationContext(), workFolder);
                //                  Log.i(Prefs.TAG, "License check RC: " + rc);
                //                  new Thread (new Runnable() {
                //                        @Override
                //                        public void run() {
                //                           List<File> lf = FileUtil.getFiles(selectedFiles);
                //                           for (File f : lf) {
                //                              Log.i(Prefs.TAG, "f = " + f);
                //                              synchronized (command) {
                //                                 convertingFile = f.getAbsolutePath();
                //                                 Log.i(Prefs.TAG, convertingFile + "2=" + convertingFile);
                //                                 runTranscoding();
                //                                 while (!progresssBarFinished) {
                //                                    try {
                //                                       Thread.sleep(250);
                //                                    } catch (InterruptedException e) {}
                //                                 }
                //                              }
                //                           }
                //                        }
                //                  }).start();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to convert");
                //                     statusView.setText("Nothing to convert");
                //                  }
                //               }
            }
        }
    } catch (Throwable t) {
        Log.e("onActivityResult", t.getMessage(), t);
    }
    Log.d("onActivityResult.load", load + " onActivityResult");
    webView.requestFocus();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateLists(@NotNull final List<Task> checkedTasks) {
    final ArrayList<String> contexts = new ArrayList<String>();
    Set<String> selectedContexts = new HashSet<String>();
    final TaskCache taskbag = getTaskBag();
    contexts.addAll(Util.sortWithPrefix(taskbag.getContexts(), m_app.sortCaseSensitive(), null));
    for (Task t : checkedTasks) {
        selectedContexts.addAll(t.getLists());
    }// ww  w .ja  v  a 2s .  c o m

    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            contexts.toArray(new String[contexts.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    for (String context : selectedContexts) {
        int position = contexts.indexOf(context);
        if (position != -1) {
            lv.setItemChecked(position, true);
        }
    }

    final EditText ed = (EditText) view.findViewById(R.id.editText);
    m_app.setEditTextHint(ed, R.string.new_list_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> originalLines = new ArrayList<String>();
            originalLines.addAll(Util.tasksToString(getCheckedTasks()));
            ArrayList<String> items = new ArrayList<String>();
            ArrayList<String> uncheckedItesm = new ArrayList<String>();
            uncheckedItesm.addAll(Util.getCheckedItems(lv, false));
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                for (Task t : checkedTasks) {
                    t.addList(item);
                }
            }
            for (String item : uncheckedItesm) {
                for (Task t : checkedTasks) {
                    t.removeTag("@" + item);
                }
            }
            finishActionmode();
            m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.update_lists);
    dialog.show();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateTags(@NotNull final List<Task> checkedTasks) {
    final ArrayList<String> projects = new ArrayList<String>();
    Set<String> selectedProjects = new HashSet<String>();
    final TaskCache taskbag = getTaskBag();
    projects.addAll(Util.sortWithPrefix(taskbag.getProjects(), m_app.sortCaseSensitive(), null));
    for (Task t : checkedTasks) {
        selectedProjects.addAll(t.getTags());
    }/*ww  w  .j a  v  a  2  s. c  o m*/

    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            projects.toArray(new String[projects.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    for (String context : selectedProjects) {
        int position = projects.indexOf(context);
        if (position != -1) {
            lv.setItemChecked(position, true);
        }
    }

    final EditText ed = (EditText) view.findViewById(R.id.editText);
    m_app.setEditTextHint(ed, R.string.new_tag_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> items = new ArrayList<String>();
            ArrayList<String> originalLines = new ArrayList<String>();
            originalLines.addAll(Util.tasksToString(checkedTasks));
            ArrayList<String> uncheckedItems = new ArrayList<String>();
            uncheckedItems.addAll(Util.getCheckedItems(lv, false));
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                for (Task t : checkedTasks) {
                    t.addTag(item);
                }
            }
            for (String item : uncheckedItems) {
                for (Task t : checkedTasks) {
                    t.removeTag("+" + item);
                }
            }
            finishActionmode();
            m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.update_tags);
    dialog.show();
}

From source file:com.free.searcher.MainFragment.java

public boolean preview(MenuItem item) {
    //         final Dialog dialog = new Dialog(CountingFragment.this);
    //         dialog.setContentView(R.layout.preview);
    //         dialog.setTitle("Preview");
    ////from   w  ww .  j av  a  2 s .c o m
    //         Button okBtn = (Button) dialog.findViewById(R.id.okBtn);
    //         okBtn.setOnClickListener(new OnClickListener() {
    //
    //               @Override
    //               public void onClick(View v) {
    //                  EditText preview = (EditText) dialog.findViewById(R.id.preview);
    //                  CountingFragment.this.charsPreview =
    //                     Integer.valueOf(preview.getText().toString());
    //                  diaLog.dismiss();
    //               }
    //            });
    //
    //         Button cancelBtn = (Button) dialog.findViewById(R.id.cancelBtn);
    //         cancelBtn.setOnClickListener(new OnClickListener() {
    //
    //               @Override
    //               public void onClick(View v) {
    //                  diaLog.dismiss();
    //               }
    //            });
    //         dialog.show();

    LayoutInflater factory = LayoutInflater.from(activity);
    final View textEntryView = factory.inflate(R.layout.preview, null);
    final EditText preview = (EditText) textEntryView.findViewById(R.id.preview);
    preview.setText("" + MainActivity.charsPreview);
    AlertDialog dialog = new AlertDialog.Builder(activity).setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.charsPreview).setView(textEntryView)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    try {
                        MainActivity.charsPreview = Integer.valueOf(preview.getText().toString());
                    } catch (NumberFormatException nfe) {
                        showToast("Invalid number. Keep the old value " + MainActivity.charsPreview);
                    }
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
    dialog.show();
    return true;
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

private void showPickProgressDialog(final List<BookProgress> results) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(getString(R.string.cloud_bm));

    ProgressListAdapter adapter = new ProgressListAdapter(context, bookView, results);
    builder.setAdapter(adapter, adapter);

    AlertDialog dialog = builder.create();
    dialog.setOwnerActivity(getActivity());
    dialog.show();//from w  w w . j  av a 2s . c o m
}

From source file:com.free.searcher.MainFragment.java

public boolean clearCache(MenuItem item) {

    AlertDialog.Builder alert = new AlertDialog.Builder(activity);
    alert.setTitle("Clear Caching Files");
    long[] entry = new long[] { 0, 0, 0 };
    FileUtil.getDirSize(MainFragment.PRIVATE_DIR, entry);
    alert.setMessage("Cache has " + MainFragment.nf.format(entry[2]) + " folders, "
            + MainFragment.nf.format(entry[0]) + " files, " + MainFragment.nf.format(entry[1]) + " bytes. "
            + "\r\nAre you sure you want to clear the cached files? "
            + "\r\nAfter cleaning searching will be slow for the first times "
            + "and the searching task maybe incorrect.");
    alert.setCancelable(true);// w  ww.j a v a  2 s.  c o  m

    alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.d("Cleaning files",
                    FileUtil.deleteFiles(MainFragment.PRIVATE_DIR, MainFragment.LINE_SEP, true, ""));
        }
    });

    alert.setPositiveButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    AlertDialog alertDialog = alert.create();
    alertDialog.show();
    return true;
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

private void showSearchResultDialog(final List<SearchResult> results) {

    if (isSearchResultsDialogShowing) {
        return;//from   w w  w  .  jav  a2s.c om
    }

    isSearchResultsDialogShowing = true;

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.search_results);

    SearchResultAdapter adapter = new SearchResultAdapter(context, bookView, results);
    builder.setAdapter(adapter, adapter);

    AlertDialog dialog = builder.create();
    dialog.setOwnerActivity(getActivity());
    dialog.setOnDismissListener(d -> isSearchResultsDialogShowing = false);
    dialog.show();
}