3

如何在我的应用程序中添加第三个按钮......我想将第三个按钮设置为“Listen”......我已经检查过了

.setNeutralButton

但它不起作用....怎么可能?

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();



 }
 });



}



}

使用 .setNeutralButton........有错误

在此处输入图像描述

没有 .setNeutralButton....没有错误

在此处输入图像描述

4

3 回答 3

3

只需在 setNegativeButton 的 .add 之后删除分号(;)OnClickListener

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();

                        }
                    });
于 2012-07-06T11:36:11.807 回答
2

去掉分号在 setNegativeButton 之后。然后您可以添加中性按钮。

于 2012-07-06T11:38:25.987 回答
-1

尝试这个....

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

现在尝试设置按钮,您将获得三个按钮

于 2012-07-06T11:39:52.240 回答