3

How can i add a 3rd button in my application......i want to set a third button as "Listen"....i am already check

.setNeutralButton

But it does not work....how can it possible?

public class MessageViewPage extends Activity {

ScrollView sv;
String nickname,body;
private LinearLayout mainLayout;
final Context context = this;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.message_view_page);

    Bundle b = getIntent().getExtras();

    nickname= b.getString("nick");
    body=b.getString("body");

    System.out.println(nickname);
    System.out.println(body);

    mainLayout=(LinearLayout)findViewById(R.id.mainLayoutmess);

    mainLayout.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            System.out.println("***************in on click************");

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

                // set title
                alertDialogBuilder.setTitle("Access");

                // set dialog message
                alertDialogBuilder
                    .setMessage("What's next?")
                    .setCancelable(false)
                    .setPositiveButton("Reply",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {

                            Intent i=new Intent(MessageViewPage.this,Reply.class);
                            startActivity(i);
                            finish();

                        }
                      })
                    .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {

                            dialog.cancel();

                        }
                    });


                    // create alert dialog
                    AlertDialog alertDialog = alertDialogBuilder.create();

                    // show it
                    alertDialog.show();



 }
 });



}



}

with .setNeutralButton........having error

enter image description here

without .setNeutralButton....no error

enter image description here

Dipin.K.G
  • 127
  • 10
  • 1
    What you need is a custom dialog. Here is how to get it done [http://stackoverflow.com/questions/5544405/android-custom-dialog][1] [1]: http://stackoverflow.com/questions/5544405/android-custom-dialog – the100rabh Jul 06 '12 at 11:36
  • 1
    refer this link for custom dialog http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog,tis one for question http://www.androidhive.info/2011/09/how-to-show-alert-dialog-in-android/ – KMI Jul 06 '12 at 11:39
  • By defining **Custom dialog**, you can have as many as buttons you want. – Paresh Mayani Jul 06 '12 at 11:40

3 Answers3

3

JUST remove semicolon(;) after setNegativeButton's OnClickListener .add as:

alertDialogBuilder
                    .setMessage("What's next?")
                    .setCancelable(false)
                    .setPositiveButton("Reply",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {

                            Intent i=new Intent(MessageViewPage.this,Reply.class);
                            startActivity(i);
                            finish();

                        }
                      })
                    .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {

                            dialog.cancel();

                        }
                    }) // ; remove this semicolon here
 .setNeutralButton("Neutral",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {

                            dialog.cancel();

                        }
                    });
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
2

Remove the semicolon ; after setNegativeButton. Then you can add the NeutralButton.

Benito Bertoli
  • 25,285
  • 12
  • 54
  • 61
-1

Try this....

 AlertDialog alert=new AlertDialog.Builder(adminpage.this).create();

now try to set button you will get three buttons

elsa
  • 396
  • 1
  • 13