Tutorial: Modal Dialogs

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: Done :)

Postby nbagade » Fri Nov 20, 2009 8:46 am

It wll be very helpfull.
Nice article
Nbagade




[quote="darolla"]Well, thats it :D

I hope you understand my code and my explainations.

For questions just post here or write me a pm.

Thanks for reading.

Greetings,
DaRolla

PS: feel free to use the attached code.

PSS: I've found the beer picture [url=https://www.scripps.edu/services/sof/social/HappyHours.html]here[/url].[/quote]
nbagade
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Fri Nov 20, 2009 7:49 am
Location: India

Top

Nice

Postby 3layn » Fri Nov 27, 2009 7:40 am

Good one !,

although i am experience a small problem, in your listener tutorial, the below is used as stated in the tutorial, but when i press OK the only thing that happens is that the view dialog dissapears - hence the app is still running. I want it to shutdown and force me back to main menu or homescreen.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        public void onClick(View v) {
  2.  
  3.          dialog.dismiss();
  4.  
  5.        }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
User avatar
3layn
Freshman
Freshman
 
Posts: 2
Joined: Fri Nov 27, 2009 7:37 am
Location: Sweden

Postby Zeba Momin » Sat Dec 05, 2009 10:44 am

hii...
Thank you..for dis lovely tutorial...great wrk...!!! :)
I dnt want my popup dialog to hav ne title bar....can u plzzzzz tell me how do i do dis???
Thank you....
Zeba Momin
Developer
Developer
 
Posts: 49
Joined: Thu Sep 17, 2009 6:53 am

Postby enggvipin.singh » Sun Dec 13, 2009 1:01 am

Does anybody have the answer of 3layn's question?

I am also looking for the same -how can i completely exit from application with a click of button?

regards
vipin
User avatar
enggvipin.singh
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 12, 2009 4:16 pm
Location: INDIA

Postby Jim Cobb » Wed Dec 16, 2009 2:48 pm

enggvipin.singh wrote:Does anybody have the answer of 3layn's question?

I am also looking for the same -how can i completely exit from application with a click of button?

regards
vipin


Couldn't you pass the Activity into your Dialog constructor, then call <Activity>.finish(); on it from the button click listener? I'm not at my development computer to try it at the moment, but it seems like that should work...

Jim
Jim Cobb
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Dec 16, 2009 2:44 pm
Location: Atlanta, GA

Postby Richa » Thu Mar 11, 2010 1:34 pm

hello.......
I have problem in getting the editText value from the dialog box...
can you just let me knw how to get that........


The code is:

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup aboutview = (ViewGroup) inflater.inflate(R.layout.pop_up, null);
EditText e= (EditText)aboutview.findViewById(R.id.number1);
e.setText("hello");// m getting a null here...

Plz help ... :(
Richa
Freshman
Freshman
 
Posts: 3
Joined: Tue Jan 12, 2010 11:44 am

Top

Nice tutorial

Postby jetaber » Thu Mar 25, 2010 1:08 am

But I have a problem when I try to follow the example and apply it to my own app: it does not block. I need to pause my application, allow the user to provide some additional information, pass the information back to the calling app and then allow the calling app to continue.
jetaber
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 22, 2010 6:07 pm

Re: Nice tutorial

Postby songotho » Thu Mar 25, 2010 8:10 am

jetaber wrote:But I have a problem when I try to follow the example and apply it to my own app: it does not block. I need to pause my application, allow the user to provide some additional information, pass the information back to the calling app and then allow the calling app to continue.


Which problem did u get? I think that u can use new Intent to make ur application.
U can follow this code to create the dialog and add something u want:
Code: Select all
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
ViewGroup aboutview = (ViewGroup) inflater.inflate(R.layout.pop_up, null);

Goodluck.
Alex.
songotho
Experienced Developer
Experienced Developer
 
Posts: 55
Joined: Tue Mar 03, 2009 1:59 am

Re: Second

Postby bertignac » Mon Apr 19, 2010 3:00 pm

darolla wrote:
It's not possible (please correct me if I'm wrong) to add some XML to the AlertDialog.Builder.

DaRolla


It seems to be possible as it is written in the official android dev guide http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Take a look after third topic (end of the guide) on the page above.

Regards,

bertignac
bertignac
Junior Developer
Junior Developer
 
Posts: 14
Joined: Thu Feb 11, 2010 7:18 pm

Postby sampath_sl » Thu May 06, 2010 8:16 pm

Thank you very much Mr.darolla. This tutorial simplifies the mastery of Android Dialog boxes. Great tutorial.
sampath_sl
Developer
Developer
 
Posts: 35
Joined: Sun Apr 11, 2010 4:45 pm
Location: Colombo

Re: Tutorial: Modal Dialogs

Postby sqwirly » Mon May 31, 2010 3:34 am

Hi,
Your examples have been really great. I am still having a problem with my dialog box. I simply want to modify a string depending which button is pressed in the dialog box. I've declared globalstring at the top of the class. When I click either "Yes" or "No" the dialog closes but globalstring is never modified.

Here is part of my code below. Is there a better way of doing this? THANKS!!!!:

String answer="";
new AlertDialog.Builder(this)
.setTitle("Test")
.setMessage("Ready?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
globalstring="Yes has been clicked";
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
globalstring="No has been clicked";
}
})
.show();
answer=globalstring;
sqwirly
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 31, 2010 3:28 am

Re: Tutorial: Modal Dialogs

Postby syed-hammad-ali » Thu Jun 10, 2010 11:33 am

This thread prove to be very useful, Thanks all;
her my question is;
in my dialog I have a simple input field that takes user email; with two buttons 1. "Submit ", 2. "Cancle"
and I need to control the dialog dismiss operation.
below attached code do not have any dismiss() function call, But either i press cancle or Submit Dialog gets disapper. I need to control the dialog hide/show during email validation.

This is the Layout XML "alert_email_subscription"
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    android:layout_width="fill_parent"
  3.    android:layout_height="wrap_content"
  4.    android:orientation="vertical">
  5.  
  6.     <TextView
  7.        android:layout_height="wrap_content"
  8.        android:layout_width="wrap_content"
  9.        android:layout_marginLeft="20dip"
  10.        android:layout_marginRight="20dip"
  11.        android:text="@string/email_title"
  12.        android:gravity="left"
  13.        android:textAppearance="?android:attr/textAppearanceMedium"
  14.         />
  15.     <EditText
  16.        android:id="@+id/emailEditTextNew"
  17.        android:layout_height="wrap_content"
  18.        android:layout_width="fill_parent"
  19.        android:layout_marginLeft="20dip"
  20.        android:layout_marginRight="20dip"
  21.        android:scrollHorizontally="true"
  22.        android:singleLine="true"
  23.        android:autoText="false"
  24.        android:capitalize="none"
  25.        android:gravity="fill_horizontal"
  26.        android:textAppearance="?android:attr/textAppearanceMedium"
  27.         />
  28. </LinearLayout>
  29.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
  1. LayoutInflater factory = LayoutInflater.from(Main.this); 
  2. final View textEntryView = factory.inflate(R.layout.alert_email_subscription, null); 
  3.  
  4. AlertDialog d = new AlertDialog.Builder(Main.this) 
  5. .setIcon(R.drawable.android_icon) 
  6. .setTitle(getString(R.string.email_toptitle)) 
  7. .setCancelable(false) 
  8. .setView(textEntryView) 
  9. .setNeutralButton( 
  10. getText(R.string.submit_button_text),// Label  
  11. new DialogInterface.OnClickListener() { 
  12. public void onClick(DialogInterface dialog, int whichButton) { 
  13. EditText emailEditText = (EditText) textEntryView.findViewById(R.id.emailEditTextNew);  
  14. String email = emailEditText.getText().toString().trim(); 
  15. Log.d(Tag, "Email is :: " + email); 
  16. if ( email.equals("")) { 
  17. Log.d(Tag, "Provide the email"); 
  18. //((AlertDialog.Builder)dialog).setMessage("Provide the email"); 
  19. // HERE I need to STOP closing the Dialog; 
  20. else if(ClientUtil.validateEmail(email)){ 
  21. Log.d(Tag, "Invalid email"); 
  22. //((AlertDialog.Builder)dialog).setMessage("Invalid email"); 
  23. // HERE I need to STOP closing the Dialog; 
  24. } else { 
  25. subscribeEmail(email);  
  26. .setNegativeButton( 
  27. getText(R.string.cancel_button_text),// Label  
  28. new DialogInterface.OnClickListener() { 
  29. public void onClick(DialogInterface dialog, int whichButton) { 
  30. finish(); 
  31. .create(); 
  32. d.show(); 

syed-hammad-ali
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Jun 10, 2010 11:20 am

Re: Second

Postby mishkin » Sat Dec 25, 2010 10:14 pm

darolla wrote: It's not possible (please correct me if I'm wrong) to add some XML to the AlertDialog.Builder.
DaRolla


DaRolla, thanks for the nice tutorial. But you are not quite right here - you can use AlertDialog just fine with XML layouts and the best part to retain all the features of AlertDialog like positive/negative buttons and other goodies.

Scroll down to this page to see how to do that:
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
mishkin
Freshman
Freshman
 
Posts: 2
Joined: Sat Dec 25, 2010 10:04 pm

Re: Tutorial: Modal Dialogs

Postby Rachit27 » Fri Mar 04, 2011 5:26 am

Hi,
I have implemented TouchEventHandler for an activity that has a CameraPreview. If I display a Dialog on top of that activity how can I close it when the user touches on the Dialog?
Rachit27
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Mar 04, 2011 5:15 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests