SlideShare a Scribd company logo
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 (20)

PPTX
Visual studio ide componects dot net framwork
Dipen Parmar
 
PPT
Basic using of Swing in Java
suraj pandey
 
PDF
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
PPTX
Java swing
Apurbo Datta
 
PPTX
GUI programming
Vineeta Garg
 
PDF
Intake 38 8
Mahmoud Ouf
 
DOCX
Lecture6 oopj
Dhairya Joshi
 
PDF
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
PPT
Swing and AWT in java
Adil Mehmoood
 
PDF
Gui builder
learnt
 
PPTX
Java- GUI- Mazenet solution
Mazenetsolution
 
PPT
Awt and swing in java
Shehrevar Davierwala
 
PPTX
Java swing and events
Prathamesh sawant
 
PPTX
XMetaL Dialog Odds & Ends
XMetaL
 
PDF
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
PPTX
Complete java swing
jehan1987
 
PPTX
SPF WinForm Programs
Hock Leng PUAH
 
PPSX
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
Rohit malav
 
PPT
java2 swing
guest0282b71
 
PPT
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 
Visual studio ide componects dot net framwork
Dipen Parmar
 
Basic using of Swing in Java
suraj pandey
 
Windows Forms For Beginners Part - 4
Bhushan Mulmule
 
Java swing
Apurbo Datta
 
GUI programming
Vineeta Garg
 
Intake 38 8
Mahmoud Ouf
 
Lecture6 oopj
Dhairya Joshi
 
Windows Forms For Beginners Part 5
Bhushan Mulmule
 
Swing and AWT in java
Adil Mehmoood
 
Gui builder
learnt
 
Java- GUI- Mazenet solution
Mazenetsolution
 
Awt and swing in java
Shehrevar Davierwala
 
Java swing and events
Prathamesh sawant
 
XMetaL Dialog Odds & Ends
XMetaL
 
Windows Forms For Beginners Part - 3
Bhushan Mulmule
 
Complete java swing
jehan1987
 
SPF WinForm Programs
Hock Leng PUAH
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
Rohit malav
 
java2 swing
guest0282b71
 
Basic of Abstract Window Toolkit(AWT) in Java
suraj pandey
 

Viewers also liked (18)

ODP
Asynctasks
Anthony Dahanne
 
PPTX
BroadcastReceivers in Android
Perfect APK
 
PPTX
Sqlite Multiple Table
Danang Kukuh Pribadi
 
ODP
Android App Development - 07 Threading
Diego Grancini
 
PPTX
Android async task
Madhu Venkat
 
PPTX
Android service, aidl - day 1
Utkarsh Mankad
 
PDF
Deep dive into android restoration - DroidCon Paris 2014
Paris Android User Group
 
PPTX
Thread management
Ayaan Adeel
 
PPT
Lecture Slides for Preferences and Menus [Android ]
Nehil Jain
 
PDF
Android service
Kirill Rozov
 
PDF
Android Threading
Jussi Pohjolainen
 
PDF
AndroidManifest
Ahsanul Karim
 
PPTX
Android intents, notification and broadcast recievers
Utkarsh Mankad
 
PPT
Android - Thread, Handler and AsyncTask
Hoang Ngo
 
PDF
Android intents
Siva Ramakrishna kv
 
PPTX
Efficient Android Threading
Anders Göransson
 
PPTX
Android - Intents - Mazenet Solution
Mazenetsolution
 
PPTX
Creating apps that work on all screen sizes
Ravi Vyas
 
Asynctasks
Anthony Dahanne
 
BroadcastReceivers in Android
Perfect APK
 
Sqlite Multiple Table
Danang Kukuh Pribadi
 
Android App Development - 07 Threading
Diego Grancini
 
Android async task
Madhu Venkat
 
Android service, aidl - day 1
Utkarsh Mankad
 
Deep dive into android restoration - DroidCon Paris 2014
Paris Android User Group
 
Thread management
Ayaan Adeel
 
Lecture Slides for Preferences and Menus [Android ]
Nehil Jain
 
Android service
Kirill Rozov
 
Android Threading
Jussi Pohjolainen
 
AndroidManifest
Ahsanul Karim
 
Android intents, notification and broadcast recievers
Utkarsh Mankad
 
Android - Thread, Handler and AsyncTask
Hoang Ngo
 
Android intents
Siva Ramakrishna kv
 
Efficient Android Threading
Anders Göransson
 
Android - Intents - Mazenet Solution
Mazenetsolution
 
Creating apps that work on all screen sizes
Ravi Vyas
 
Ad

Similar to Android Dialogs Tutorial (20)

PPTX
Alert Dialog Box in Android for mca students
TheRockyFF
 
PPTX
Android Lab Test : Creating a dialog Yes/No (english)
Bruno Delb
 
PPTX
MAD_lecture-DialogBoxesrejgjgjgkhkhkhk.pptx
himanshunanobhatt
 
PDF
Android basic 3 Dialogs
Eakapong Kattiya
 
DOCX
Android basics – dialogs and floating activities
info_zybotech
 
PPTX
Lecture 7: Android Kinds of Dialogs.pptx
Yousef Alamir
 
PDF
Android session 3
Ahesanali Suthar
 
DOCX
Android-dialogs in android-chapter14
Dr. Ramkumar Lakshminarayanan
 
PPT
Progress Dialog, AlertDialog, CustomDialog
Sourabh Sahu
 
ODP
Android App Development - 11 Lists, grids, adapters, dialogs and toasts
Diego Grancini
 
PPTX
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
PDF
Android App Development 03 : Widget &amp; UI
Anuchit Chalothorn
 
PPTX
Android App Development (Basics)
Alberto Rubalcaba Stockman
 
PPTX
Android Development for Beginners with Sample Project - Day 1
Joemarie Amparo
 
PDF
Mobile Application Development -Lecture 09 & 10.pdf
AbdullahMunir32
 
PPT
Android
San Bunna
 
PPT
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
PPT
android dilaogs
Deepa Rani
 
PPTX
Android Development Made Easy - With Sample Project
Joemarie Amparo
 
PDF
Android development training programme , Day 3
DHIRAJ PRAVIN
 
Alert Dialog Box in Android for mca students
TheRockyFF
 
Android Lab Test : Creating a dialog Yes/No (english)
Bruno Delb
 
MAD_lecture-DialogBoxesrejgjgjgkhkhkhk.pptx
himanshunanobhatt
 
Android basic 3 Dialogs
Eakapong Kattiya
 
Android basics – dialogs and floating activities
info_zybotech
 
Lecture 7: Android Kinds of Dialogs.pptx
Yousef Alamir
 
Android session 3
Ahesanali Suthar
 
Android-dialogs in android-chapter14
Dr. Ramkumar Lakshminarayanan
 
Progress Dialog, AlertDialog, CustomDialog
Sourabh Sahu
 
Android App Development - 11 Lists, grids, adapters, dialogs and toasts
Diego Grancini
 
07.3. Android Alert message, List, Dropdown, and Auto Complete
Oum Saokosal
 
Android App Development 03 : Widget &amp; UI
Anuchit Chalothorn
 
Android App Development (Basics)
Alberto Rubalcaba Stockman
 
Android Development for Beginners with Sample Project - Day 1
Joemarie Amparo
 
Mobile Application Development -Lecture 09 & 10.pdf
AbdullahMunir32
 
Android
San Bunna
 
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
android dilaogs
Deepa Rani
 
Android Development Made Easy - With Sample Project
Joemarie Amparo
 
Android development training programme , Day 3
DHIRAJ PRAVIN
 
Ad

Recently uploaded (20)

PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

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();