setClickOnListener中的警告对话框未显示

时间:2011-10-09 09:31:48

标签: android alertdialog

这是我的班级

    public class TeamUpAttack extends OrmLiteBaseActivity<DatabaseHelper> {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.teamup_attack);
 /* more code */
            Button toComplete = (Button) findViewById(R.id.attack_confirm);
            toComplete.setOnClickListener(toCompleteH);
 /* more code */
        }

/* more code */

        View.OnClickListener toCompleteH = new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    List<Player> pl = getHelper().getPlayerDao().query( getHelper().getPlayerDao().queryBuilder().where().not().eq("Posizione", "NA").prepare() );
                    Log.e("TEAMUPATTACCK", v.getClass().getCanonicalName());
                    if(pl.size()==11) v.getContext().startActivity(new Intent(v.getContext(), GeneratedFormation.class));
                    else {
                        AlertDialog.Builder alert_bld;

                        alert_bld = new AlertDialog.Builder(TeamUpAttack.this);
                        alert_bld.setNegativeButton("OK", new DialogInterface.OnClickListener(){
                            public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                            }
                        });
                        AlertDialog alert = alert_bld.create();
                        alert.setMessage("You must choose 11 players");
                        alert.setIcon(R.drawable.icon);

                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        };

 /* more code */

    }

我应该将什么作为参数传递给建造者?

2 个答案:

答案 0 :(得分:4)

我认为你缺少alertdialog.show()方法,它显示了控件

http://developer.android.com/reference/android/app/AlertDialog.Builder.html

答案 1 :(得分:2)

您必须在show()上调用AlertDialog方法。