mobile computing lecture#11 adapters and dialogs
TRANSCRIPT
![Page 1: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/1.jpg)
Mobile Computing
Lecture#11 Adapters and Dialogs
![Page 2: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/2.jpg)
Lecture Contents Adapter
SimpleCursorAdapter ArrayAdapter
Dialog Dialog Class Dialog-themed Activity Toasts
2
![Page 3: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/3.jpg)
AdaptersAdapters are bridging classes that bind data to
Views (such as List Views) used in the user interface.
The adapter is responsible for 1. Creating the child Views used to represent each
item within the parent View (say a ListView)2. Providing access to the underlying data (say an
ArrayList)
3
![Page 4: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/4.jpg)
Simple Cursor Adapter An easy adapter to map columns from a
cursor to TextViews or ImageViews You can specify which columns you want,
which views you want to display the columns, and the XML file that defines the appearance of these views.
4
![Page 5: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/5.jpg)
Simple Cursor Adapte Example
5
![Page 6: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/6.jpg)
Simple Cursor Adapte Example
6
![Page 7: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/7.jpg)
ArrayAdapter The Array Adapter uses generics to bind an
Adapter View to an array of objects of the specified class
By default the Array Adapter uses the toString() value of each object in the array to create and populate Text Views
Alternative constructors enable you to use more complex layouts
You can even extend the class to use alternatives to Text Views (to display data)
7
![Page 8: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/8.jpg)
ArrayAdapter ExampleSteps Involved::::1. Layout Definitions2. Adapter Class3. Activity to show elements
8
![Page 9: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/9.jpg)
ArrayAdapter Example (Adapter Class)
9
![Page 10: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/10.jpg)
10
ArrayAdapter Example (Main Class)
![Page 11: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/11.jpg)
ArrayAdapter Example (row.xml)
11
![Page 12: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/12.jpg)
ArrayAdapter Example (main.xml)
12
![Page 13: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/13.jpg)
ArrayAdapter Example (Output)
13
![Page 14: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/14.jpg)
ArrayAdapter Complex ExampleSteps Involved::::1. Layout Definitions2. View Data Class3. Adapter Class4. Activity to show elements
14
![Page 15: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/15.jpg)
Layouts
15
![Page 16: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/16.jpg)
Data
Cla
ss
16
![Page 17: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/17.jpg)
Student Adapter
17
![Page 18: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/18.jpg)
Main
18
![Page 19: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/19.jpg)
Dialogs Dialog boxes are a common UI metaphor in
desktop, web, and mobile applications They’re used to help users answer
questions, make selections, and confirm actions, and to display warning or error messages
Dialog boxes in Android are partially transparent, floating Activities that appear upon activities that launch them
19
![Page 20: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/20.jpg)
Implementing DialogsThere are three ways to implement a dialog in
Android: 1. Using Dialog class2. Dialog-themed Activity3. Toasts
20
![Page 21: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/21.jpg)
Using Dialog Class or Its Extensions Android includes a number of specialist
classes that extend Dialog Each is designed to provide specific dialog-box
functionality Dialog-class-based screen is constructed
entirely within its calling Activity, so it doesn’t need to be registered in the manifest
Dialog’s life cycle is controlled entirely by the calling Activity
21
![Page 22: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/22.jpg)
Dialog CreationDialog d = new Dialog(MyActivity.this);// Have the new window tint and blur the window it obscures.
Window window = d.getWindow();int flag =
WindowManager.LayoutParams.FLAG_BLUR_BEHIND;window.setFlags(flag, flag); d.setTitle("Dialog Title"); // Set title
d.setContentView(R.layout.dialog_view); // Inflate layout
// Find the TextView used in the layout and set its text value
TextView text = (TextView)d.findViewById(R.id.dialog);text.setText("This is the text in my dialog");d.show();
22
![Page 23: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/23.jpg)
Dialog output
23
![Page 24: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/24.jpg)
Dia
log w
ith B
utto
ns
final Context context = Main.this;String title = "It is Pitch Black";String message = "You are likely to be eaten by a ghost";String button1String = "Go Back";String button2String = "Move Forward"; AlertDialog.Builder ad = new AlertDialog.Builder(context); ad.setTitle(title); d.setMessage(message); ad.setPositiveButton(button1String, new DialogInterface.OnClickListener()
{ public void onClick(DialogInterface dialog, int arg1) { //Do something positive } }); ad.setNegativeButton(button2String, new
DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int arg1) {
//Do something negative }});ad.show();
24
![Page 25: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/25.jpg)
Dia
log w
ith B
utto
ns
25
![Page 26: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/26.jpg)
Toast Android allows us to display a message without
any button like 'OK' or 'Cancel' Its helps us to display a short message in short
time Call Toast.makeText() Provide necessary arguments
(Context, Message, Duration) Call show() message to display toast
26
![Page 27: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/27.jpg)
Syntax/Example
27
Toast SyntaxToast.makeText(Context, Message,
Duration).show()
ToastExample:::::Toast.makeText(MyActivity.this, “You have been
assigned a project”, Toast.LENGTH_LONG).show();
![Page 28: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/28.jpg)
Custom ToastToast toast = new Toast(MyActivity.this);TextView toastView = new TextView(MyActivity.this);toastView.setText("Here goes your message");toastView.setBackgroundColor(Color.WHITE);toastView.setTextColor(Color.RED);toastView.setPadding(10,10,10,10);toast.setView(toastView);toast.setDuration(Toast.LENGTH_LONG);toast.setGravity(Gravity.CENTER, 0, 0);toast.show();
28
![Page 29: Mobile Computing Lecture#11 Adapters and Dialogs](https://reader036.vdocuments.mx/reader036/viewer/2022081506/56649ea05503460f94ba3f65/html5/thumbnails/29.jpg)
Regular/Custom Toast
29