SlideShare a Scribd company logo
1 of 7
Android Dialogs
Perfect APK
Android Dialogs Tutorial
Popups or dialogs are a common to prompt the user to take action. Android popups are called Dialogs. The base dialog class is extended by
AlertDialog class, which is extended by more specific dialog classes:
● DatePickerDialog
● ProgressDialog
● TimePickerDialog
In this tutorial we will create AlertDialogs using the AlertDialog.Builder helper class.
AlertDialogs are divided into the following components:
● Title Area
● Content Area
● Buttons - Positive, negative and neutral
None of the components are mandatory, and for each components there is a default view. In this tutorial we will see 3 examples:
● Single-Choice Dialog
● Dialog with buttons
Single-Choice Dialog
This example uses the following default components:
● Title Area - The default title view which is actually a TextView. The view is set using the setTitle() method of the AlertDialog.Builder class.
● Content Area - The default single-choice ListView which is actually a RadioGroup. The view is set using the setSingleChoiceItems() method of
the AlertDialog.Builder class.
The AlertDialog in this example is created using the following code:
1. builder = new AlertDialog.Builder(mContext);
2. builder.setTitle(R.string.dialog_single_choice_title);
3. builder.setSingleChoiceItems(R.array.color_names, mSingleChoicePosition, this);
4. mAlertDialog = builder.create();
5. mAlertDialog.show();
The color_names array is described in the res/values/color_names.xml file below:
1. <?xml version="1.0" encoding="utf-8"?>
2. <resources>
Dialog With Buttons
This example uses the following default components:
● Title Area - The default title view which is actually a TextView. The view is set using the setTitle() method of the
AlertDialog.Builder class.
● Content Area - The default message view which is actually a TextView. The view is set using the setMessage() method of the
AlertDialog.Builder class.
● Buttons - Positive and Negative buttons are set using the setPositiveButton() and setNegativeButton() methods of the
AlertDialog.Builder class.
The AlertDialog in this example is created using the following code:
1. builder = new AlertDialog.Builder(mContext);
2. builder.setTitle(R.string.dialog_with_buttons_title);
3. builder.setMessage(R.string.dialog_with_buttons_message);
4. builder.setPositiveButton(R.string.dialog_with_buttons_positive, this);
Custom Dialog
This example uses only the content component, for the following res/layout/custom_dialog.xml file is used:
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent" >
5.
6. <TextView android:id="@+id/tvTitle"
7. android:layout_width="match_parent"
8. android:layout_height="wrap_content"
9. android:padding="5dp"
10. android:text="@string/dialog_custom_title"
11. android:textAppearance="@android:style/TextAppearance.Medium.Inverse"
Custom Dialog
1. <TextView android:id="@+id/tvContent"
2. android:layout_width="match_parent"
3. android:layout_height="wrap_content"
4. android:layout_below="@id/tvTitle"
5. android:text="@string/dialog_custom_text"
6. android:textAppearance="@android:style/TextAppearance.Large"
7. android:gravity="center"
8. android:textStyle="bold|italic"
9. android:paddingTop="20dp"
10. android:paddingBottom="20dp" />
11.
12. <RatingBar android:id="@+id/ratingBar"
Custom Dialog
The AlertDialog in this example is created using the following code:
1. LayoutInflater inflater = LayoutInflater.from(mContext);
2. builder = new AlertDialog.Builder(mContext);
3. builder.setTitle(null);
4. View customDialogView = inflater.inflate(R.layout.custom_dialog, null, false);
5. RatingBar ratingBar = (RatingBar) customDialogView.findViewById(R.id.ratingBar);
6. ratingBar.setRating(mRating);
7. ratingBar.setOnRatingBarChangeListener(this);
8. builder.setView(customDialogView);
9. mAlertDialog = builder.create();
10. mAlertDialog.show();

More Related Content

What's hot

Visual studio ide componects dot net framwork
Visual studio ide componects dot net framworkVisual studio ide componects dot net framwork
Visual studio ide componects dot net framworkDipen Parmar
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Javasuraj pandey
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Bhushan Mulmule
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Bhushan Mulmule
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in javaAdil Mehmoood
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solutionMazenetsolution
 
XMetaL Dialog Odds & Ends
XMetaL Dialog Odds & EndsXMetaL Dialog Odds & Ends
XMetaL Dialog Odds & EndsXMetaL
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Bhushan Mulmule
 
Complete java swing
Complete java swingComplete java swing
Complete java swingjehan1987
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAVRohit malav
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Javasuraj pandey
 

What's hot (20)

Visual studio ide componects dot net framwork
Visual studio ide componects dot net framworkVisual studio ide componects dot net framwork
Visual studio ide componects dot net framwork
 
Basic using of Swing in Java
Basic using of Swing in JavaBasic using of Swing in Java
Basic using of Swing in Java
 
Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4Windows Forms For Beginners Part - 4
Windows Forms For Beginners Part - 4
 
Java swing
Java swingJava swing
Java swing
 
GUI programming
GUI programmingGUI programming
GUI programming
 
Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
Lecture6 oopj
Lecture6 oopjLecture6 oopj
Lecture6 oopj
 
Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5Windows Forms For Beginners Part 5
Windows Forms For Beginners Part 5
 
Swing and AWT in java
Swing and AWT in javaSwing and AWT in java
Swing and AWT in java
 
Gui builder
Gui builderGui builder
Gui builder
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
Java swing and events
Java swing and eventsJava swing and events
Java swing and events
 
XMetaL Dialog Odds & Ends
XMetaL Dialog Odds & EndsXMetaL Dialog Odds & Ends
XMetaL Dialog Odds & Ends
 
Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3Windows Forms For Beginners Part - 3
Windows Forms For Beginners Part - 3
 
Complete java swing
Complete java swingComplete java swing
Complete java swing
 
SPF WinForm Programs
SPF WinForm ProgramsSPF WinForm Programs
SPF WinForm Programs
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
 
java2 swing
java2 swingjava2 swing
java2 swing
 
Basic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in JavaBasic of Abstract Window Toolkit(AWT) in Java
Basic of Abstract Window Toolkit(AWT) in Java
 

Viewers also liked

BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in AndroidPerfect APK
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
Android async task
Android async taskAndroid async task
Android async taskMadhu Venkat
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1Utkarsh Mankad
 
Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Paris Android User Group
 
Thread management
Thread management Thread management
Thread management Ayaan Adeel
 
Lecture Slides for Preferences and Menus [Android ]
Lecture Slides for Preferences and Menus [Android ]Lecture Slides for Preferences and Menus [Android ]
Lecture Slides for Preferences and Menus [Android ]Nehil Jain
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recieversUtkarsh Mankad
 
Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskHoang Ngo
 
Android - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionAndroid - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionMazenetsolution
 
Creating apps that work on all screen sizes
Creating apps that work on all screen sizesCreating apps that work on all screen sizes
Creating apps that work on all screen sizesRavi Vyas
 

Viewers also liked (18)

Asynctasks
AsynctasksAsynctasks
Asynctasks
 
BroadcastReceivers in Android
BroadcastReceivers in AndroidBroadcastReceivers in Android
BroadcastReceivers in Android
 
Sqlite Multiple Table
Sqlite Multiple TableSqlite Multiple Table
Sqlite Multiple Table
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Android async task
Android async taskAndroid async task
Android async task
 
Android service, aidl - day 1
Android service, aidl - day 1Android service, aidl - day 1
Android service, aidl - day 1
 
Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014Deep dive into android restoration - DroidCon Paris 2014
Deep dive into android restoration - DroidCon Paris 2014
 
Thread management
Thread management Thread management
Thread management
 
Lecture Slides for Preferences and Menus [Android ]
Lecture Slides for Preferences and Menus [Android ]Lecture Slides for Preferences and Menus [Android ]
Lecture Slides for Preferences and Menus [Android ]
 
Android service
Android serviceAndroid service
Android service
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android intents, notification and broadcast recievers
Android intents, notification and broadcast recieversAndroid intents, notification and broadcast recievers
Android intents, notification and broadcast recievers
 
Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTask
 
Android intents
Android intentsAndroid intents
Android intents
 
Efficient Android Threading
Efficient Android ThreadingEfficient Android Threading
Efficient Android Threading
 
Android - Intents - Mazenet Solution
Android - Intents - Mazenet SolutionAndroid - Intents - Mazenet Solution
Android - Intents - Mazenet Solution
 
Creating apps that work on all screen sizes
Creating apps that work on all screen sizesCreating apps that work on all screen sizes
Creating apps that work on all screen sizes
 

Similar to Android Dialogs Tutorial

Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAnuchit Chalothorn
 
Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Bruno Delb
 
Android basics – dialogs and floating activities
Android basics – dialogs and floating activitiesAndroid basics – dialogs and floating activities
Android basics – dialogs and floating activitiesinfo_zybotech
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidShrijan Tiwari
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAhsanul Karim
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogsDeepa Rani
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
PDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTPDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTNAVYA RAO
 
Oracle 10g Forms Lesson 15
Oracle 10g Forms Lesson  15Oracle 10g Forms Lesson  15
Oracle 10g Forms Lesson 15KAMA3
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210Mahmoud Samir Fayed
 

Similar to Android Dialogs Tutorial (20)

Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UI
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Android session 3
Android session 3Android session 3
Android session 3
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
 
Android UI
Android UIAndroid UI
Android UI
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)
 
Android basics – dialogs and floating activities
Android basics – dialogs and floating activitiesAndroid basics – dialogs and floating activities
Android basics – dialogs and floating activities
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
 
android dilaogs
android dilaogsandroid dilaogs
android dilaogs
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 
PDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPTPDF ON JAVA - JFC CONCEPT
PDF ON JAVA - JFC CONCEPT
 
08ui.pptx
08ui.pptx08ui.pptx
08ui.pptx
 
Les14
Les14Les14
Les14
 
Oracle 10g Forms Lesson 15
Oracle 10g Forms Lesson  15Oracle 10g Forms Lesson  15
Oracle 10g Forms Lesson 15
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210The Ring programming language version 1.9 book - Part 82 of 210
The Ring programming language version 1.9 book - Part 82 of 210
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Android Dialogs Tutorial

  • 2. Android Dialogs Tutorial Popups or dialogs are a common to prompt the user to take action. Android popups are called Dialogs. The base dialog class is extended by AlertDialog class, which is extended by more specific dialog classes: ● DatePickerDialog ● ProgressDialog ● TimePickerDialog In this tutorial we will create AlertDialogs using the AlertDialog.Builder helper class. AlertDialogs are divided into the following components: ● Title Area ● Content Area ● Buttons - Positive, negative and neutral None of the components are mandatory, and for each components there is a default view. In this tutorial we will see 3 examples: ● Single-Choice Dialog ● Dialog with buttons
  • 3. Single-Choice Dialog This example uses the following default components: ● Title Area - The default title view which is actually a TextView. The view is set using the setTitle() method of the AlertDialog.Builder class. ● Content Area - The default single-choice ListView which is actually a RadioGroup. The view is set using the setSingleChoiceItems() method of the AlertDialog.Builder class. The AlertDialog in this example is created using the following code: 1. builder = new AlertDialog.Builder(mContext); 2. builder.setTitle(R.string.dialog_single_choice_title); 3. builder.setSingleChoiceItems(R.array.color_names, mSingleChoicePosition, this); 4. mAlertDialog = builder.create(); 5. mAlertDialog.show(); The color_names array is described in the res/values/color_names.xml file below: 1. <?xml version="1.0" encoding="utf-8"?> 2. <resources>
  • 4. Dialog With Buttons This example uses the following default components: ● Title Area - The default title view which is actually a TextView. The view is set using the setTitle() method of the AlertDialog.Builder class. ● Content Area - The default message view which is actually a TextView. The view is set using the setMessage() method of the AlertDialog.Builder class. ● Buttons - Positive and Negative buttons are set using the setPositiveButton() and setNegativeButton() methods of the AlertDialog.Builder class. The AlertDialog in this example is created using the following code: 1. builder = new AlertDialog.Builder(mContext); 2. builder.setTitle(R.string.dialog_with_buttons_title); 3. builder.setMessage(R.string.dialog_with_buttons_message); 4. builder.setPositiveButton(R.string.dialog_with_buttons_positive, this);
  • 5. Custom Dialog This example uses only the content component, for the following res/layout/custom_dialog.xml file is used: 1. <?xml version="1.0" encoding="utf-8"?> 2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3. android:layout_width="match_parent" 4. android:layout_height="match_parent" > 5. 6. <TextView android:id="@+id/tvTitle" 7. android:layout_width="match_parent" 8. android:layout_height="wrap_content" 9. android:padding="5dp" 10. android:text="@string/dialog_custom_title" 11. android:textAppearance="@android:style/TextAppearance.Medium.Inverse"
  • 6. Custom Dialog 1. <TextView android:id="@+id/tvContent" 2. android:layout_width="match_parent" 3. android:layout_height="wrap_content" 4. android:layout_below="@id/tvTitle" 5. android:text="@string/dialog_custom_text" 6. android:textAppearance="@android:style/TextAppearance.Large" 7. android:gravity="center" 8. android:textStyle="bold|italic" 9. android:paddingTop="20dp" 10. android:paddingBottom="20dp" /> 11. 12. <RatingBar android:id="@+id/ratingBar"
  • 7. Custom Dialog The AlertDialog in this example is created using the following code: 1. LayoutInflater inflater = LayoutInflater.from(mContext); 2. builder = new AlertDialog.Builder(mContext); 3. builder.setTitle(null); 4. View customDialogView = inflater.inflate(R.layout.custom_dialog, null, false); 5. RatingBar ratingBar = (RatingBar) customDialogView.findViewById(R.id.ratingBar); 6. ratingBar.setRating(mRating); 7. ratingBar.setOnRatingBarChangeListener(this); 8. builder.setView(customDialogView); 9. mAlertDialog = builder.create(); 10. mAlertDialog.show();