[TinyTut] How to use AlertDialog.Builder

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

[TinyTut] How to use AlertDialog.Builder

Postby tum0rc0re » Mon Feb 25, 2008 8:29 pm

Source code this example is here - http://www.maximyudin.com/?p=32 . Sorry that I post code on my blog, simply here's very long format a source code.

It’s a tiny example about an using of alert dialogs (viz, AlertDialog.Builder). If you want to supplement this sample by some material, write me please.

ImageImage
ImageImage
JQ Soft web page:
[b][url=http://jqsoft.ru/]http://jqsoft.ru/[/url][/b]
My proffesional blog: [b][url=http://maximyudin.blogspot.com]http://maximyudin.blogspot.com[/url][/b]
Facebook: [b][url=http://www.facebook.com/maxim.yudin]http://www.facebook.com/maxim.yudin[/url][/b]
User avatar
tum0rc0re
Senior Developer
Senior Developer
 
Posts: 158
Joined: Sun Nov 25, 2007 7:15 am
Location: Moscow, Russia

Top

Postby venkat » Tue Mar 18, 2008 4:20 pm

Thanks you very much tum0rc0re,
this post is very very help full to me :) :idea:
Regards,
Venkat.
venkat
Senior Developer
Senior Developer
 
Posts: 152
Joined: Tue Nov 27, 2007 5:42 am
Location: India

Re: [TinyTut] How to use AlertDialog.Builder

Postby tuhack » Wed Dec 24, 2008 4:05 am

Thank you for your tutorial. It's useful for me
tuhack
Freshman
Freshman
 
Posts: 5
Joined: Tue Dec 23, 2008 10:13 am

Postby digitalspaghetti » Sat Jan 10, 2009 8:52 pm

This was a very handy tutorial, thank very much
digitalspaghetti
Freshman
Freshman
 
Posts: 6
Joined: Sun Jan 04, 2009 11:52 pm

Postby Helios » Sat Jan 17, 2009 7:17 am

Hi, thanks for the tutorial, it's any possibility that I could see the XML files?
Helios
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am

.setMessage()

Postby sm12 » Sun Jan 18, 2009 8:17 pm

Good Day!

I wanted to display an instructional message (a couple of sentences) with AlertDialog.Builder
Hence, I created string value under res/values/string.xml, because my text is long.

The problem is [font=Courier New]setMessage[/font]("CharSequence"), therefore I cannot write setMessage(R.string.text);

Any tricks OR other solutions?

TIA,
sm12
Freshman
Freshman
 
Posts: 7
Joined: Thu Nov 13, 2008 4:36 am

Top

setMessage()

Postby sm12 » Sun Jan 18, 2009 9:05 pm

For the above I've tried:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. String text = R.string.text //However, I had to do = String.valueOf(R.string.text); because it's int in R
  3.  
  4.  
  5.  
  6. ...
  7.  
  8. .setMessage(text);
  9.  
  10. ...
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


But it gave me number. How do I assign value which is in [font=Courier New]string.xml [/font]through R.java or any other way?
sm12
Freshman
Freshman
 
Posts: 7
Joined: Thu Nov 13, 2008 4:36 am

Postby MrSnowflake » Sun Jan 18, 2009 11:07 pm

That's because R.string.bla is a long... :s

use String lala = getString(R.string.bla); ...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Silent_Noise » Thu Aug 06, 2009 2:40 am

Hi, everybody.
Hmmm...
My code is:
public void alert(){
new AlertDialog.Builder(reg.this)
.setMessage("Please, insert all needed information")
.setNeutralButton("Cancel",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton)
{
}
})
.show();
}

OnClickListener btnOnClick = new OnClickListener() {
public void onClick(View v) {
log=txt_log.getText();
pass=txt_pass.getText();
if ((log!=null)&(pass!=null)){
showDate();
return;
}
else{
alert();
return;
}
}
};

It doesn't work. Where is my mistake?
Silent_Noise
Freshman
Freshman
 
Posts: 3
Joined: Fri Jul 31, 2009 5:54 am
Location: Russia

Postby bryce » Sun Aug 16, 2009 11:43 pm

Thanks for the good examples!
bryce
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Aug 16, 2009 11:24 pm
Location: Dublin, Georgia USA

Postby fawx » Fri Sep 11, 2009 8:35 am

Hi

how do i start an sub-activity when the user click ok in the dialogue box itself?

Meaning from here:

public void onClick(DialogInterface dialog, int whichButton) {

}

writing the normal way doesnt seem to work.

like this:

Intent Myint = new Intent(this, subActivity.class);
startActivity(Myint);


thanks
fawx
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue Aug 18, 2009 4:34 am

Answer

Postby moe.ron » Sun Mar 21, 2010 6:03 pm

I know that this was posted a while ago, but it may be helpful for future users. The reason why you are having problems starting your activity is because inside the onClick listener you are no longer inside your class that is extending activity. Therefore using the "this" keyword will give you errors because it doesn't exist there.

Solutions

Activity thisClass;

public class foo extends Activity{
public void onCreate(Bundle b){
thisClass = this;
}
}

Now in your startActivity call you can use "thisClass" instead of "this".
You can also just make a call to another method inside the class where the "this" variable is instantiated.

Hope this helps
moe.ron
Once Poster
Once Poster
 
Posts: 1
Joined: Sun Mar 21, 2010 5:58 pm
Location: New Jersey

Re: [TinyTut] How to use AlertDialog.Builder

Postby pedroteixeira07 » Wed Jun 16, 2010 5:15 pm

This tutorial isin't available anymore. Can someone please post it? Thank you
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 11 guests