如何进行警告对话框活动

时间:2011-08-16 14:24:10

标签: android

当我点击按钮时,我有一个按钮,它显示带有三个选项的警告对话框。我点击第一个选项做第二个和第三个选项。在android中怎么办我是一个非常新的机器人,你有没有人可以帮我这个

这是我的代码

final CharSequence[] items = {"set", "option"};
                AlertDialog.Builder builder = new AlertDialog.Builder(ProgramInfoActivity.this);
                builder.setTitle("Share the Program");
                builder.setItems(items, new DialogInterface.OnClickListener() {   
                public void onClick(DialogInterface dialog, int item) {     
                if( set){

                }
                else if (option){

                }
                }});
                AlertDialog alert = builder.create();
                alert.show();

Thanks
raj.

2 个答案:

答案 0 :(得分:0)

这是我的代码......您可以使用它进行小的更改...只需添加另一个按钮即可。我的按钮是打开另一个屏幕....

AlertDialog ad = new AlertDialog.Builder(this).create();
ad.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface ad, int which) {
                Intent i = new Intent(PronadjiKlopuActivity.this, TrenutnaLokacija.class);
                startActivity(i);               
            }
        });

        ad.setButton(DialogInterface.BUTTON_NEGATIVE, "No",new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();

            }
        });
 ad.show();

答案 1 :(得分:0)

您必须使用setMultiChoiceItems方法。

return new AlertDialog.Builder( this )
               .setTitle( "Planets" )
               .setMultiChoiceItems( _options, _selections, new DialogSelectionClickHandler() )
               .setPositiveButton( "OK", new DialogButtonClickHandler() )
               .create();

以下参考资料将为您提供帮助:

http://labs.makemachine.net/2010/03/android-multi-selection-dialogs/

相关问题