Hi All, Let us know see, how to create an Alert Dialog inside another Alert Dialog?
Step 1: Create a Alert Dialog as i shown below and implement click Listener as i shown below
package com.san.test;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MyActivity extends Activity {
/** Called when the activity is first created. */
Context ctx=null;
Button b=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button )findViewById(R.id.test1);
ctx=this;
b.setOnClickListener(new android.view.View.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
displayAlert();
}}
);
}
public void displayAlert()
{
OnClickListener btnOnClick = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
new AlertDialog.Builder(ctx).setMessage("BUTTON_POSITIVE")
.setTitle("Alert Postive ")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
} else if(which == DialogInterface.BUTTON_NEGATIVE){
new AlertDialog.Builder(ctx).setMessage("BUTTON_NEGATIVE")
.setTitle("Alert Negative")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
} else if(which == DialogInterface.BUTTON_NEUTRAL) {
// More Info
new AlertDialog.Builder(ctx).setMessage("BUTTON_NEUTRAL")
.setTitle("Alert Neutral")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
}
}
};
AlertDialog promptInstall = new AlertDialog.Builder(ctx).setTitle("First Alert")
.setMessage(
"mY First Alert")
.setPositiveButton("OK", btnOnClick).setNegativeButton(
"Cancel", btnOnClick).setNeutralButton("More Info",
btnOnClick).create();
promptInstall.show();
}
}
See the images
Step 1: Create a Alert Dialog as i shown below and implement click Listener as i shown below
package com.san.test;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MyActivity extends Activity {
/** Called when the activity is first created. */
Context ctx=null;
Button b=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button )findViewById(R.id.test1);
ctx=this;
b.setOnClickListener(new android.view.View.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
displayAlert();
}}
);
}
public void displayAlert()
{
OnClickListener btnOnClick = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
new AlertDialog.Builder(ctx).setMessage("BUTTON_POSITIVE")
.setTitle("Alert Postive ")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
} else if(which == DialogInterface.BUTTON_NEGATIVE){
new AlertDialog.Builder(ctx).setMessage("BUTTON_NEGATIVE")
.setTitle("Alert Negative")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
} else if(which == DialogInterface.BUTTON_NEUTRAL) {
// More Info
new AlertDialog.Builder(ctx).setMessage("BUTTON_NEUTRAL")
.setTitle("Alert Neutral")
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
finish();
}
})
.show();
}
}
};
AlertDialog promptInstall = new AlertDialog.Builder(ctx).setTitle("First Alert")
.setMessage(
"mY First Alert")
.setPositiveButton("OK", btnOnClick).setNegativeButton(
"Cancel", btnOnClick).setNeutralButton("More Info",
btnOnClick).create();
promptInstall.show();
}
}
See the images
hi new one to android i did one app in that after few seconds getting "forceclose" dialog. if u know give me idea..
ReplyDeleteHi there, You have done an incredible job. I'll certainly digg it and personally suggest to my friends. I'm confident they'll be benefited from this site.
ReplyDeleteFeel free to visit my web blog :: More Help
Нellο! Someοne in my Μуspаcе grοup shаrеd thіs site with us
ReplyDeleteso Ӏ camе to chесk it out. I'm definitely enjoying the information. I'm
book-marking anԁ ωill be tweеtіng this to my
followeгs! Outstanding blog and gгeat style and ԁesign.
Also visit my web site ; buy facebook fans
Youг style is reallу unique comparеd tο other рeοple
ReplyDeleteΙ've read stuff from. Thank you for posting when you've got
the oрpоrtunity, Guesѕ I ωill just book mark thiѕ pagе.
Feel free to visit my hοmеpаgе unlοcκed phonеs
for at\u0026t ()
Appreciating the commitment you put into your blog and in depth
ReplyDeleteinformation you offer. It's awesome to come across a blog every once in a while that isn't the
same unwanted rehashed information. Great read!
I've bookmarked your site and I'm including your RSS feeds to my Google
account.
Check out my web page :: legal usa online casinos
Hello there! Would you mind if I share your blog with my twitter group?
ReplyDeleteThere's a lot of folks that I think would really enjoy your content.
Please let me know. Thank you
My blog post ... how fix your