alert dialog inside a setClickOnListener not showing

本秂侑毒 提交于 2020-01-06 04:46:09

问题


This is my class

    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 */

    }

What should I pass as an argument to the builder?


回答1:


i think you are missing alertdialog.show() method, which displays the control

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




回答2:


You have to call the show() method on the AlertDialog.



来源:https://stackoverflow.com/questions/7702591/alert-dialog-inside-a-setclickonlistener-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!