Example usage for android.app AlertDialog setButton2

List of usage examples for android.app AlertDialog setButton2

Introduction

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

Prototype

@Deprecated
public void setButton2(CharSequence text, final OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when button 2 of the dialog is pressed.

Usage

From source file:com.renren.api.connect.android.Util.java

/**
 * ???UI/* ww w  .  j av  a 2  s. c o  m*/
 * 
 * @param context
 * @param title
 * @param text
 */
public static void showAlert(Context context, String title, String text, boolean showOk) {
    AlertDialog alertDialog = new Builder(context).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(text);
    if (showOk) {
        OnClickListener listener = null;
        alertDialog.setButton2("", listener);
    }
    alertDialog.show();
}

From source file:com.iStudy.Study.Renren.Util.java

/**
 * ???UI// w w w .ja v a2  s . c om
 * 
 * @param context
 * @param title
 * @param text
 */
@SuppressWarnings("deprecation")
public static void showAlert(Context context, String title, String text, boolean showOk) {
    AlertDialog alertDialog = new Builder(context).create();
    alertDialog.setTitle(title);
    alertDialog.setMessage(text);
    if (showOk) {
        OnClickListener listener = null;
        alertDialog.setButton2("", listener);
    }
    alertDialog.show();
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

public static void deleteSeriesAlert(Context context, final CatalogueDBAdapter dbHelper, final Series series,
        final Runnable onDeleted) {

    // When we get here, we know the names are genuinely different and the old series is used in more than one place.
    String message = "Delete series";
    try {// w w w  . j av  a  2s  . c  om
        message = String.format(context.getResources().getString(R.string.really_delete_series), series.name);
    } catch (NullPointerException e) {
        Logger.logError(e);
    }
    final AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage(message).create();

    alertDialog.setTitle(R.string.delete_series);
    alertDialog.setIcon(android.R.drawable.ic_menu_info_details);
    //alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
    alertDialog.setButton2(context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dbHelper.deleteSeries(series);
                    alertDialog.dismiss();
                    onDeleted.run();
                }
            });

    //alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
    alertDialog.setButton(context.getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    alertDialog.dismiss();
                }
            });

    alertDialog.show();
}

From source file:com.eleybourn.bookcatalogue.dialogs.StandardDialogs.java

public static int deleteBookAlert(Context context, final CatalogueDBAdapter dbHelper, final long id,
        final Runnable onDeleted) {

    ArrayList<Author> authorList = dbHelper.getBookAuthorList(id);

    String title;//from  w ww  .  j a v a2 s .  co  m
    Cursor cur = dbHelper.fetchBookById(id);
    try {
        if (cur == null || !cur.moveToFirst())
            return R.string.unable_to_find_book;

        title = cur.getString(cur.getColumnIndex(CatalogueDBAdapter.KEY_TITLE));
        if (title == null || title.length() == 0)
            title = "<Unknown>";

    } finally {
        if (cur != null)
            cur.close();
    }

    // Format the list of authors nicely
    String authors;
    if (authorList.size() == 0)
        authors = "<Unknown>";
    else {
        authors = authorList.get(0).getDisplayName();
        for (int i = 1; i < authorList.size() - 1; i++) {
            authors += ", " + authorList.get(i).getDisplayName();
        }
        if (authorList.size() > 1)
            authors += " " + context.getResources().getString(R.string.list_and) + " "
                    + authorList.get(authorList.size() - 1).getDisplayName();
    }

    // Get the title      
    String format = context.getResources().getString(R.string.really_delete_book);

    String message = String.format(format, title, authors);
    final AlertDialog alertDialog = new AlertDialog.Builder(context).setMessage(message).create();

    alertDialog.setTitle(R.string.menu_delete);
    alertDialog.setIcon(android.R.drawable.ic_menu_info_details);
    //alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
    alertDialog.setButton2(context.getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dbHelper.deleteBook(id);
                    alertDialog.dismiss();
                    onDeleted.run();
                }
            });

    //alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
    alertDialog.setButton(context.getResources().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    alertDialog.dismiss();
                }
            });

    alertDialog.show();
    return 0;

}

From source file:net.networksaremadeofstring.cyllell.Search.java

public void MakeHandler() {
    handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                //TODO ListView population
                NodeAdapter = new NodeListAdaptor(Search.this, listOfNodes);
                list.setAdapter(NodeAdapter);

                //Close the Progress dialog
                dialog.dismiss();//from w w w  .j  a v a 2s  .  c  o  m
            } else if (msg.what == 200) {
                dialog.setMessage("Searching for: " + query + "\n\nSending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(Search.this).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Search.this.finish();
                    }
                });
                alertDialog.setIcon(R.drawable.error);
                alertDialog.show();
            }

        }
    };
}

From source file:com.TakeTaxi.jy.OnrouteScreen.java

public void button_drivercancel_reportlate(AlertDialog dcancelbuilder) {
    dcancelbuilder.setButton2("Yes", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String check = Query.jobQuery("drivercancellate", job_id, 0, driver_id);

            if (check.equals("done")) {
                Intent openStart = new Intent("com.TakeTaxi.jy.TakeTaxiActivity");
                startActivity(openStart);
            } else {
                Toast.makeText(getBaseContext(), "Could not connect to server.\nPlease try again.",
                        Toast.LENGTH_SHORT).show();
            }/*  www .j a v  a 2  s  .  c om*/
        }
    });
}

From source file:com.TakeTaxi.jy.OnrouteScreen.java

public void button_cancelJob_driverNoShow(AlertDialog dcancelbuilder) {
    dcancelbuilder.setButton2("Yes", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String check = Query.jobQuery("drivernoshow", job_id, 0, driver_id);

            if (check.equals("done")) {
                Intent openStart = new Intent("com.TakeTaxi.jy.TakeTaxiActivity");
                startActivity(openStart);
            } else {
                Toast.makeText(getBaseContext(), "Could not connect to server.\nPlease try again.",
                        Toast.LENGTH_SHORT).show();
            }/*from w  w w  .j a  v  a2s . c om*/

        }
    });

}

From source file:net.networksaremadeofstring.cyllell.ViewCookbooks_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {//from   w  w  w.  j  av a  2  s .co  m
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");

    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfCookbooks.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfCookbooks.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewCookbooks_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfCookbooks.get(tag).SetErrorState();
                }
            }
            CookbookAdapter.notifyDataSetChanged();
        }
    };

    handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        //selectForCAB((Integer)v.getTag());
                        Toast.makeText(getActivity(), "This version doesn't support Cookbook editing yet",
                                Toast.LENGTH_SHORT).show();
                        return true;
                    }
                };

                CookbookAdapter = new CookbookListAdaptor(getActivity(), listOfCookbooks, listener,
                        listenerLong);
                try {
                    list = (ListView) getView().findViewById(R.id.cookbooksListView);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (list != null) {
                    if (CookbookAdapter != null) {
                        list.setAdapter(CookbookAdapter);
                    } else {
                        //Log.e("CookbookAdapter","CookbookAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(context).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfCookbooks.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Cookbooks = Cut.GetCookbooks();
                    handler.sendEmptyMessage(201);
                    JSONArray Keys = Cookbooks.names();
                    String URI = "";
                    String Version = "0.0.0";
                    JSONObject cookbook;
                    for (int i = 0; i < Cookbooks.length(); i++) {
                        cookbook = new JSONObject(Cookbooks.getString(Keys.get(i).toString()));
                        //URI = Cookbooks.getString(Keys.get(i).toString()).replaceFirst("^(https://|http://).*/cookbooks/", "");
                        //Version = Cookbooks.getString(Keys.get(i).toString())
                        //Log.i("Cookbook Name", Keys.get(i).toString());
                        URI = cookbook.getString("url").replaceFirst("^(https://|http://).*/cookbooks/", "");
                        //Log.i("Cookbook URL", URI);

                        JSONArray versions = cookbook.getJSONArray("versions");

                        Version = versions.getJSONObject(versions.length() - 1).getString("version");
                        //Log.i("Cookbook version", Version);

                        listOfCookbooks.add(new Cookbook(Keys.get(i).toString(), URI, Version));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    BugSenseHandler.log("ViewCookbooksFragment", e);
                    e.printStackTrace();
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.cookbooks_landing, container, false);
}

From source file:net.networksaremadeofstring.cyllell.ViewEnvironments_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.environmentsListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {/*from   ww  w.  j  a va 2s  . c om*/
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfEnvironments.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfEnvironments.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewEnvironments_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfEnvironments.get(tag).SetErrorState();
                }
            }
            EnvironmentAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        //Log.i("OnClick","Clicked");
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                EnvironmentAdapter = new EnvironmentListAdaptor(getActivity().getBaseContext(),
                        listOfEnvironments, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.environmentsListView);
                if (list != null) {
                    if (EnvironmentAdapter != null) {
                        list.setAdapter(EnvironmentAdapter);
                    } else {
                        //Log.e("EnvironmentAdapter","EnvironmentAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfEnvironments.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Environments = Cut.GetEnvironments();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Environments.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfEnvironments.add(
                                new Environment(Keys.getString(i), Environments.getString(Keys.getString(i))
                                        .replaceFirst("^(https://|http://).*/environments/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.environments_landing, container, false);
}

From source file:net.networksaremadeofstring.cyllell.ViewRoles_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    list = (ListView) this.getActivity().findViewById(R.id.rolesListView);
    settings = this.getActivity().getSharedPreferences("Cyllell", 0);
    try {//from  w w w. jav a2 s  .c  o m
        Cut = new Cuts(getActivity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    dialog = new ProgressDialog(getActivity());
    dialog.setTitle("Contacting Chef");
    dialog.setMessage("Please wait: Prepping Authentication protocols");
    dialog.setIndeterminate(true);
    if (listOfRoles.size() < 1) {
        dialog.show();
    }

    updateListNotify = new Handler() {
        public void handleMessage(Message msg) {
            int tag = msg.getData().getInt("tag", 999999);

            if (msg.what == 0) {
                if (tag != 999999) {
                    listOfRoles.get(tag).SetSpinnerVisible();
                }
            } else if (msg.what == 1) {
                //Get rid of the lock
                CutInProgress = false;

                //the notifyDataSetChanged() will handle the rest
            } else if (msg.what == 99) {
                if (tag != 999999) {
                    Toast.makeText(ViewRoles_Fragment.this.getActivity(),
                            "An error occured during that operation.", Toast.LENGTH_LONG).show();
                    listOfRoles.get(tag).SetErrorState();
                }
            }
            RoleAdapter.notifyDataSetChanged();
        }
    };

    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            //Once we've checked the data is good to use start processing it
            if (msg.what == 0) {
                OnClickListener listener = new OnClickListener() {
                    public void onClick(View v) {
                        GetMoreDetails((Integer) v.getTag());
                    }
                };

                OnLongClickListener listenerLong = new OnLongClickListener() {
                    public boolean onLongClick(View v) {
                        selectForCAB((Integer) v.getTag());
                        return true;
                    }
                };

                RoleAdapter = new RoleListAdaptor(getActivity(), listOfRoles, listener, listenerLong);
                list = (ListView) getView().findViewById(R.id.rolesListView);
                if (list != null) {
                    if (RoleAdapter != null) {
                        list.setAdapter(RoleAdapter);
                    } else {
                        //Log.e("CookbookAdapter","CookbookAdapter is null");
                    }
                } else {
                    //Log.e("List","List is null");
                }

                dialog.dismiss();
            } else if (msg.what == 200) {
                dialog.setMessage("Sending request to Chef...");
            } else if (msg.what == 201) {
                dialog.setMessage("Parsing JSON.....");
            } else if (msg.what == 202) {
                dialog.setMessage("Populating UI!");
            } else {
                //Close the Progress dialog
                dialog.dismiss();

                //Alert the user that something went terribly wrong
                AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                alertDialog.setTitle("API Error");
                alertDialog.setMessage("There was an error communicating with the API:\n"
                        + msg.getData().getString("exception"));
                alertDialog.setButton2("Back", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        //getActivity().finish();
                    }
                });
                alertDialog.setIcon(R.drawable.icon);
                alertDialog.show();
            }
        }
    };

    Thread dataPreload = new Thread() {
        public void run() {
            if (listOfRoles.size() > 0) {
                handler.sendEmptyMessage(0);
            } else {
                try {
                    handler.sendEmptyMessage(200);
                    Roles = Cut.GetRoles();
                    handler.sendEmptyMessage(201);

                    JSONArray Keys = Roles.names();

                    for (int i = 0; i < Keys.length(); i++) {
                        listOfRoles.add(new Role(Keys.getString(i), Roles.getString(Keys.getString(i))
                                .replaceFirst("^(https://|http://).*/roles/", "")));
                    }

                    handler.sendEmptyMessage(202);
                    handler.sendEmptyMessage(0);
                } catch (Exception e) {
                    Message msg = new Message();
                    Bundle data = new Bundle();
                    data.putString("exception", e.getMessage());
                    msg.setData(data);
                    msg.what = 1;
                    handler.sendMessage(msg);
                }
            }
            return;
        }
    };

    dataPreload.start();
    return inflater.inflate(R.layout.roles_landing, container, false);
}