Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Android ; Confirm app exit
- final String phoneNumber;
- phoneNumber = "5555555555";
- ImageButton callButton = (ImageButton)findViewById(R.id.btnCall);
- callButton.setOnClickListener(new OnClickListener(){
- public void onClick(View v) {
- try {
- Intent callIntent = new Intent(Intent.ACTION_DIAL);
- callIntent.setData(Uri.parse("tel:"+phoneNumber));
- startActivity(callIntent);
- } catch (ActivityNotFoundException activityException) {
- Log.e("Calling a Phone Number", "Call failed", activityException);
- }
- }
- });
- callButton.setOnClickListener(new OnClickListener(){
- public void onClick(View v) {
- OnClickListener listener = new OnClickListener(){
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if(which == Dialog.BUTTON_POSITIVE)
- {
- try {
- Intent callIntent = new Intent(Intent.ACTION_DIAL);
- callIntent.setData(Uri.parse("tel:"+phoneNumber));
- startActivity(callIntent);
- } catch (ActivityNotFoundException activityException) {
- Log.e("Calling a Phone Number", "Call failed", activityException);
- }
- }
- }
- };
- new AlertDialog.Builder(v.getContext())
- .setMessage("Are you sure you want to leave the application?")
- .setPositiveButton("Yes", listener)
- .setNegativeButton("No", listener)
- .show();
- }
- }
- AlertDialog.Builder alert = new AlertDialog.Builder(this);
- alert.setTitle("Title");
- alert.setMessage("Message");
- // Set an EditText view to get user input
- final EditText input = new EditText(this);
- alert.setView(input);
- alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- String value = input.getText();
- // Do something with value!
- }
- });
- alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // Canceled.
- }
- });
- alert.show();
Add Comment
Please, Sign In to add comment