Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.example.fieldbokorig.RetrieveFieldbookActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    //      Dialog dialog = null;
    switch (id) {
    case DIALOG_RETRIEVE_ID:
        // Create out AlterDialog
        Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Retrieve the selected fieldbooks?");
        builder.setCancelable(true);//ww  w .j a  va 2s. c  om
        builder.setPositiveButton("Yes", new retrieveOnClickListener());
        builder.setNegativeButton("No", new cancelOnClickListener()); //use the same for both dialogs
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
        break;
    case DIALOG_DELETE_ID:
        // Delete selected fieldbook
        Builder builder2 = new AlertDialog.Builder(this);
        builder2.setMessage("Delete the selected fieldbooks?");
        builder2.setCancelable(true);
        builder2.setPositiveButton("Yes", new deleteOnClickListener());
        builder2.setNegativeButton("No", new cancelOnClickListener()); //use the same for both dialogs
        alertDialog = builder2.create();
        alertDialog.show();
        break;
    }
    return super.onCreateDialog(id);
}

From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java

protected void translate(final ParcelableStatus status) {
    ThreadPolicy tp = ThreadPolicy.LAX;
    StrictMode.setThreadPolicy(tp);/*from  w  w w .ja  v  a  2s  .  c om*/

    String language = Locale.getDefault().getLanguage();
    String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType="
            + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language
            + "&text=";
    url = url + URLEncoder.encode(status.text_plain);
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpGet(url));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();

        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        String finalString = s.toString();
        finalString = finalString
                .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
        finalString = finalString.replace("</string>", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
        builder.setTitle(getString(R.string.translate));
        builder.setMessage(finalString);
        builder.setCancelable(true);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

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

        //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/** Called when the activity is first started. */
@Override//  ww  w  . j a va2  s  .com
public void onCreate(Bundle bundle) {
    Log.d(LOG_TAG, "entering onCreate()");
    SettingsActivity.setTheme(this);
    super.onCreate(bundle);
    setContentView(R.layout.main);

    try {
        busNet = BusNetwork.getInstance(this);
    } catch (Exception e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        return;
    }

    // get the button
    // set handler to launch a processing dialog
    ImageButton updateButton = (ImageButton) findViewById(R.id.update_button);
    updateButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            BusLine selectedLine = lineAdapter.getItem(lineSpinner.getSelectedItemPosition());
            BusStop selectedStop = stopAdapter.getItem(stopSpinner.getSelectedItemPosition());
            getBusTimings(selectedLine, selectedStop);
        }
    });

    ImageButton feedbackButton = (ImageButton) findViewById(R.id.feedback_button);
    feedbackButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822"); // use from live device
            i.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FEEDBACK_EMAIL_ADDRESS });
            i.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_EMAIL_SUBJECT);
            i.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_hello));
            startActivity(Intent.createChooser(i, getString(R.string.select_email_app)));
        }
    });

    ImageButton phebusinfoButton = (ImageButton) findViewById(R.id.phebusinfo_button);
    phebusinfoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog alertDialog = new AlertDialog.Builder(NextBusMain.this).create();
            WebView wv = new WebView(NextBusMain.this);
            new PhebusNewsLoader(wv, NextBusMain.this).execute();
            alertDialog.setView(wv);
            alertDialog.show();
        }
    });

    lineSpinner = (Spinner) findViewById(R.id.line_spinner);
    lineAdapter = new ArrayAdapter<BusLine>(this, android.R.layout.simple_spinner_item, busNet.getLines());
    lineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    lineSpinner.setAdapter(lineAdapter);

    stopSpinner = (Spinner) findViewById(R.id.stop_spinner);
    stopAdapter = new ArrayAdapter<BusStop>(this, android.R.layout.simple_spinner_item);
    stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    stopSpinner.setAdapter(stopAdapter);

    ImageButton favoriteButton = (ImageButton) findViewById(R.id.favorites_button);
    favoriteButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            new FavoriteDialog(NextBusMain.this, new OnFavoriteSelectedListener() {
                @Override
                public void favoriteSelected(Favorite fav) {
                    BusLine bl = busNet.getLineByName(fav.getLine());
                    BusStop bs = bl.getFirstStopWithSimilarName(fav.getStop());
                    if (bl == null || bs == null) {
                        Log.e(LOG_TAG, "Favorite not found!");
                        return;
                    }
                    updateSpinners(bl, bs);
                    getBusTimings(bl, bs);
                }
            }, lineSpinner.getSelectedItem().toString(), stopSpinner.getSelectedItem().toString());
        }
    });
}

From source file:es.uja.photofirma.android.SignUpActivity.java

/**
 * Advertencia a cerca de la privacidad del usuario, el usuario ser notificado
 * /* w  ww .  j  a v  a 2s.  c  o  m*/
 */
public void onTermsOfUse(View view) {
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Terminos de uso");
    alertDialog.setMessage(getString(R.string.terms_of_use));
    alertDialog.setCancelable(false);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

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

}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false);

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice);
    lv = (ListView) rootView.findViewById(R.id.list);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
    lvItems = (ListView) rootView.findViewById(R.id.lvItems);

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  w w.j a  v  a  2 s.  c  o m*/
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input);
            edit_title.setHint(R.string.title_hint);

            final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input);
            edit_cont.setHint(R.string.text_hint);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTitle = edit_title.getText().toString().trim();
                    String inputCont = edit_cont.getText().toString().trim();

                    if (db.isExist(inputTitle)) {
                        Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
                    } else {
                        db.insert(inputTitle, inputCont, "", "", helper_main.createDate());
                        dialog.dismiss();
                        setRandomList();
                        Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show();
                    }
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_random");
            startActivity(mainIntent);
        }
    });

    fab_dice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            try {
                Random rand = new Random();
                final int n = rand.nextInt(lvItems.getCount());

                setAdapter(n);
                lvItems.setSelection(n - 1);

            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
    });

    //calling Notes_DbAdapter
    db = new Random_DbAdapter(getActivity());
    db.open();

    setRandomList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:com.abc.driver.PersonalActivity.java

public void updatePortait(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(res.getString(R.string.choose_portrait));
    builder.setItems(new String[] { res.getString(R.string.getPhotoFromCamera),
            res.getString(R.string.getPhotoFromMemory) }, new DialogInterface.OnClickListener() {
                // @Override
                public void onClick(DialogInterface dialog, int id) {
                    switch (id) {
                    case 0:
                        startToCameraActivity(CellSiteConstants.TAKE_USER_PORTRAIT);
                        break;
                    case 1:
                        startToMediaActivity(CellSiteConstants.PICK_USER_PORTRAIT);
                        break;
                    }//ww w  .j ava  2  s  . c o  m
                }

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

From source file:com.abc.driver.PersonalActivity.java

public void updateDriverLicense(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(res.getString(R.string.choose_portrait));
    builder.setItems(new String[] { res.getString(R.string.getPhotoFromCamera),
            res.getString(R.string.getPhotoFromMemory) }, new DialogInterface.OnClickListener() {
                // @Override
                public void onClick(DialogInterface dialog, int id) {
                    switch (id) {
                    case 0:
                        startToCameraActivity(CellSiteConstants.TAKE_DRIVER_LICENSE);
                        break;
                    case 1:
                        startToMediaActivity(CellSiteConstants.PICK_DRIVER_LICENSE);
                        break;
                    }/*from   w w  w  .  j  a va  2s  . c o  m*/
                }

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

From source file:com.abc.driver.PersonalActivity.java

public void updateIdentityImage(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(res.getString(R.string.choose_portrait));
    builder.setItems(new String[] { res.getString(R.string.getPhotoFromCamera),
            res.getString(R.string.getPhotoFromMemory) }, new DialogInterface.OnClickListener() {
                // @Override
                public void onClick(DialogInterface dialog, int id) {
                    switch (id) {
                    case 0:
                        startToCameraActivity(CellSiteConstants.TAKE_IDENTITY);
                        break;
                    case 1:
                        startToMediaActivity(CellSiteConstants.PICK_IDENTITY);
                        break;
                    }// w ww.  ja v  a 2 s .c  o  m
                }

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

From source file:mp.paschalis.WatchBookActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    app = (App) getApplication();/*  ww  w .j  a  va  2 s.c o  m*/

    setContentView(R.layout.activity_watch_book);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Get arguments, to determine who opened this activity
    final Bundle extras = getIntent().getExtras();

    try {
        isAvailable = extras.getBoolean(App.ExtrasForWatchBookActivityFromBookSearch);
    } catch (Exception e) {
        isAvailable = false;
    }

    // Set the layout's data
    // Get layout's Data
    bookISBN = (TextView) findViewById(R.id.textViewBookISBN);

    bookTitle = (TextView) findViewById(R.id.textViewBookTitle);
    bookAuthors = (TextView) findViewById(R.id.textViewBookAuthors);
    bookPublishedYear = (TextView) findViewById(R.id.textViewBookPublishedYear);
    bookPageCount = (TextView) findViewById(R.id.textViewBookPageCount);
    bookDateOfInsert = (TextView) findViewById(R.id.textViewBookDateOfInsert);

    bookCoverImage = (ImageView) findViewById(R.id.imageViewBookCover);

    bookLanguage = (TextView) findViewById(R.id.textViewBookLanguage);

    textViewWatchBookAvailable = (TextView) findViewById(R.id.textViewWatchBookAvailable);

    buttonRequestBook = (Button) findViewById(R.id.buttonRequestBook);

    buttonSendMessage = (Button) findViewById(R.id.buttonSendMessage);
    progressBarSendMessage = (ProgressBar) findViewById(R.id.progressBarSendMessage);

    buttonSendMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final DataClassRequestABook dataClassRequestABook = new DataClassRequestABook();

            dataClassRequestABook.username = app.user.username;
            dataClassRequestABook.isbn = app.selectedBook.isbn;

            ArrayList<String> userWhoLent = new ArrayList<String>();
            // Find all users who lent this book
            for (Book.DataClassUser u : app.selectedBook.owners) {
                if (u.status == 0) {
                    userWhoLent.add(u.username);
                }
            }

            final CharSequence[] owners = userWhoLent.toArray(new CharSequence[userWhoLent.size()]);

            AlertDialog.Builder builder = new AlertDialog.Builder(WatchBookActivity.this);
            builder.setTitle(R.string.msgPickBookOwner_);
            builder.setItems(owners, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {

                    dataClassRequestABook.owner = (String) owners[item];

                    // Send message to owner
                    Intent intent = new Intent(WatchBookActivity.this, SendMessageActivity.class);

                    intent.putExtra(App.ExtrasForSendMessage_DestinationUser, dataClassRequestABook.owner);

                    startActivity(intent);

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

    });

    if (!isAvailable) {
        textViewWatchBookAvailable.setText(R.string.no);
        App.setStyleErrorDirection(textViewWatchBookAvailable);
        buttonRequestBook.setEnabled(false);
    } else {

        textViewWatchBookAvailable.setText(R.string.yes);
        App.setStyleSuccessDirection(textViewWatchBookAvailable);

        // Requests a book
        buttonRequestBook.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                {

                    final DataClassRequestABook dataClassRequestABook = new DataClassRequestABook();

                    dataClassRequestABook.username = app.user.username;
                    dataClassRequestABook.isbn = app.selectedBook.isbn;

                    ArrayList<String> userWhoLent = new ArrayList<String>();
                    // Find all users who lent this book
                    for (Book.DataClassUser u : app.selectedBook.owners) {
                        if (u.status == 0) {
                            userWhoLent.add(u.username);
                        }
                    }

                    final CharSequence[] owners = userWhoLent.toArray(new CharSequence[userWhoLent.size()]);

                    AlertDialog.Builder builder = new AlertDialog.Builder(WatchBookActivity.this);
                    builder.setTitle(R.string.msgPickBookOwner_);
                    builder.setItems(owners, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int item) {

                            dataClassRequestABook.owner = (String) owners[item];

                            // Request the book
                            new AsyncTaskRequestABook().execute(dataClassRequestABook);

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

            }
        });// End of Req Button!

    }

    TextView tvnc = (TextView) findViewById(R.id.textViewNoCover);
    ProgressBar pb = (ProgressBar) findViewById(R.id.progressBarLoadCover);

    // show The Image and save it to Library
    ImageLoader.DataClassDisplayBookCover bk = new ImageLoader.DataClassDisplayBookCover();
    bk.iv = bookCoverImage;
    bk.isCover = true;
    bk.tv = tvnc;
    bk.pb = pb;
    bk.book = app.selectedBook;
    App.imageLoader.DisplayCover(bk);

    bitmapBookCover = ((BitmapDrawable) bookCoverImage.getDrawable()).getBitmap();

    // new DownloadImageTask(bookCoverImage, bookInfo)
    // .execute(bookInfo.imgURL);

    // Assign the appropriate data from our alert object above
    bookISBN.setText(app.selectedBook.isbn);
    bookTitle.setText(app.selectedBook.title);
    bookAuthors.setText(app.selectedBook.authors);
    bookPublishedYear.setText(Integer.valueOf(app.selectedBook.publishedYear).toString());
    bookPageCount.setText(Integer.valueOf(app.selectedBook.pageCount).toString());
    bookDateOfInsert
            .setText(App.makeTimeStampHumanReadble(getApplicationContext(), app.selectedBook.dateOfInsert));
    bookLanguage.setText(app.selectedBook.lang);

    progressBarRequestBook = (ProgressBar) findViewById(R.id.progressBarRequestBook);

    buttonRequestBook = (Button) findViewById(R.id.buttonRequestBook);

}

From source file:system.info.reader.java

public void showMyDialog(String[] valuse) {
    ArrayAdapter itemAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, valuse);
    View myView = getLayoutInflater().inflate(R.layout.popup, (ViewGroup) findViewById(R.id.popup_root));
    ListView itemView = (ListView) myView.findViewById(R.id.PropertyList);
    itemView.setAdapter(itemAdapter);/*from   w  w w  .  j ava2  s  . c o  m*/
    itemView.setOnItemClickListener(msubitemCL);
    AlertDialog altDialog = new AlertDialog.Builder(this).setView(myView).create();
    altDialog.setOnKeyListener(null);
    m_altDialog = altDialog;
    altDialog.show();
}