how to create alert box with multiple buttons ?

Put your problem here if it does not fit any of the other categories.

how to create alert box with multiple buttons ?

Postby ranjit0046 » Sat Jan 09, 2010 6:35 am

Hi Friends,
i was trying to create pop up alert box with multiple buttons, i created with single button alert box ,can you please suggest me , how to create it .........., i am using this code





public class Alertbox extends Activity{

@Override

public void onCreate(Bundle band)

{
super.onCreate(band);
alertbox("ranjit","welcome to india");
}
protected void alertbox(String title, String mymessage)
{
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setNeutralButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setNeutralButton(android.R.string.ok,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.show();
}


}


Ranjit.......................
ranjit0046
Developer
Developer
 
Posts: 47
Joined: Mon Dec 14, 2009 12:46 pm

Top

Postby jwei512 » Sat Jan 09, 2010 10:16 am

You can't set two neutral buttons.

Instead you want to do something like:

Posted: Sat Jan 09, 2010 6:35 am Post subject: how to create alert box with multiple buttons ?
Hi Friends,
i was trying to create pop up alert box with multiple buttons, i created with single button alert box ,can you please suggest me , how to create it .........., i am using this code





public class Alertbox extends Activity{

@Override

public void onCreate(Bundle band)

{
super.onCreate(band);
alertbox("ranjit","welcome to india");
}
protected void alertbox(String title, String mymessage)
{
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setPositiveButton("Yes!",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setNeutralButton(android.R.string.ok,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setNegativeButton("No!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
}).show();
}

This should create an alert dialog with 3 buttons, and you can set the text for each button as well as the onClickListener
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby ranjit0046 » Tue Jan 12, 2010 11:40 am

jwei512 wrote:You can't set two neutral buttons.

Instead you want to do something like:

Posted: Sat Jan 09, 2010 6:35 am Post subject: how to create alert box with multiple buttons ?
Hi Friends,
i was trying to create pop up alert box with multiple buttons, i created with single button alert box ,can you please suggest me , how to create it .........., i am using this code





public class Alertbox {

@Override

public void onCreate(Bundle band)

{
super.onCreate(band);
alertbox("ranjit","welcome to india");
}
public static void alertbox(String title, String mymessage,this)
{
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setPositiveButton("Yes!",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setNeutralButton(android.R.string.ok,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.setNegativeButton("No!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
}).show();
}

This should create an alert dialog with 3 buttons, and you can set the text for each button as well as the onClickListener





ok , thanks for your suggestion , me to find this error , Now i have another problem i invoke this form another Activity by passing "this" as a parameter in a thread in that Activity . please look bellow code


from an activity
=============

Thread t = new Thread(){
public void run()
{
Alertbox.alertbox(title, mymessage,this);
Log.i("Sample Activity class"," ====== "+samp);

}
}
t.start();

but it rises the fallowing exception



01-12 16:09:15.580: WARN/System.err(720): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
01-12 16:09:15.590: WARN/System.err(720): at android.os.Handler.<init>(Handler.java:121)
01-12 16:09:15.600: WARN/System.err(720): at android.app.Dialog.<init>(Dialog.java:99)
01-12 16:09:15.600: WARN/System.err(720): at android.app.AlertDialog.<init>(AlertDialog.java:63)
01-12 16:09:15.642: WARN/System.err(720): at android.app.AlertDialog.<init>(AlertDialog.java:59)
01-12 16:09:15.649: WARN/System.err(720): at android.app.AlertDialog$Builder.create(AlertDialog.java:786)
01-12 16:09:15.660: WARN/System.err(720): at android.app.AlertDialog$Builder.show(AlertDialog.java:801)
01-12 16:09:15.669: WARN/System.err(720): at test.app.QueryTest.alertbox(QueryTest.java:76)
01-12 16:09:15.669: WARN/System.err(720): at test.app.Alertbox.alertbox(Alertbox.java:45)
01-12 16:09:15.669: WARN/System.err(720): at test.app.Alertbox$1.run(Alertbox.java:31)
01-12 16:09:15.730: WARN/IInputConnectionWrapper(606): showStatusIcon on inactive InputConnection


plese help me ,it is urgent for my project


Ranjit....
ranjit0046
Developer
Developer
 
Posts: 47
Joined: Mon Dec 14, 2009 12:46 pm

Postby jwei512 » Wed Jan 13, 2010 7:34 am

Let A be the name of your Activity class.

Instead of passing "this", try passing "A.this"
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby ranjit0046 » Fri Jan 22, 2010 3:48 pm

jwei512 wrote:Let A be the name of your Activity class.

Instead of passing "this", try passing "A.this"




Thanks for helping
ranjit0046
Developer
Developer
 
Posts: 47
Joined: Mon Dec 14, 2009 12:46 pm

Re: how to create alert box with multiple buttons ?

Postby ranjan » Mon Jun 28, 2010 5:13 pm

I have tried with A.this but doesn't work. Please, help me.
ranjan
Developer
Developer
 
Posts: 35
Joined: Tue Nov 03, 2009 3:29 pm

Top

Re: how to create alert box with multiple buttons ?

Postby anarche » Mon Jun 28, 2010 10:15 pm

instead of A use the name of your activity, so <Activity>.this
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 30 guests