Download presentation
Presentation is loading. Please wait.
Published byDoreen Howard Modified over 9 years ago
1
User notification Android Club 2015
2
Agenda Toast Custom Toast Notification Dialog
3
Toast: example Toast.makeText(getApplicationContext(), “Hello Android”, Toast.LENGTH_LONG).show();
4
Toast: practice Create new button Text: Say hello Set OnClickListener Toast: “Hello [YOUR_NAME]!”
5
Custom Toast: example Toast toast = new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); View view = getLayoutInflater().inflate(R.layout.toast_hell o, null); toast.setView(view); toast.show();
6
Custom Toast: practice Create new Button Text: Say hello Set OnClickListener OnClick: show one small image and text For example: Just do it!
7
Notification 5 steps Create PendingIntent Create Notification setLatestEventInfo() NotificationManager Notify
8
Notification: example Intent intent = new Intent(this, MainActivity.class); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0); Notification notification = new Notification(R.drawable.friend, "Text1", System.currentTimeMillis()); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(getApplicationContext(), "Text2", "Text3", pending); // Send the notification. NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, notification);
9
Notification: practice Create PendingIntent which goes to FriendActivity Ticker text: “Friend: hello” Title: Your friend name Content: Message content
10
Dialog AlertDialog ProgressDialog DatePickerDialog TimePickerDialog
11
AlertDialog step-by-step Create AlertDialog builder setTitle setMessage setPositiveButton setNegativeButton Create AlertDialog from builder show
12
AlertDialog: example AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( MainActivity.this); // set title alertDialogBuilder.setTitle("Delete"); // set dialog message alertDialogBuilder.setMessage("Do you want to delete this file?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity MainActivity.this.finish(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show();
13
AlertDialog: practice Show AlertDialog Title: Exit app Message: Do you want to exit app Positive: Exit Negative: No, I love this app
14
Progress Dialog: example ProgressDialog dialog = ProgressDialog.show(this, "Downloading", "Downloading very big file", true); dialog.setCancelable(true); dialog.show();
15
ProgressDialog: practice Show ProgressDialog Title: Distance Message: Calculating Distance from Tashkent to Tokyo Cancelable: true
16
Homework 1: Toast Show Toast: “This is toast”
17
Homework 2: Custom Toast Create layout for toast Put text: This is toast Put image: Toaster image Show custom Toast using that layout
18
Homework 3: Notification Show notification Icon: GooglePlay Ticker text: Updating app Message: Updating telegram app Content: Updating telegram app to the new version: 2.2.2
19
Homework 4: AlertDialog Title: Terms of service Message: Are you agree with terms of service? Positive: I agree (open new activity) Negative: I do not agree (close app) setCancelable: false
20
Homework 5: ProgressDialog Show ProgressDialog Title: AndroidClub Message: Learning Android =)
21
Questions? Any questions?
22
Thank you Thank you for your attention!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.