Android setClickOnListener中的警报对话框未显示
这是我的课Android setClickOnListener中的警报对话框未显示,android,android-alertdialog,Android,Android Alertdialog,这是我的课 public class TeamUpAttack extends OrmLiteBaseActivity<DatabaseHelper> { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.te
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 */
}
public class TeamUpAttack扩展了OrmLiteBaseActivity{
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.teamup\u攻击);
/*更多代码*/
按钮完成=(按钮)查找视图id(R.id.attack\u confirm);
setOnClickListener(toComplete);
/*更多代码*/
}
/*更多代码*/
View.OnClickListener tocomplete=new View.OnClickListener(){
公共void onClick(视图v){
试一试{
List pl=getHelper().getPlayerDao().query(getHelper().getPlayerDao().queryBuilder().where().not().eq(“Posizione”,“NA”).prepare());
Log.e(“teamupattack”,v.getClass().getCanonicalName());
if(pl.size()==11)v.getContext().startActivity(新意图(v.getContext(),GeneratedFormation.class));
否则{
AlertDialog.Builder alert\u bld;
alert_bld=新建AlertDialog.Builder(TeamUpAttack.this);
alert_bld.setNegativeButton(“确定”,新建DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
dialog.cancel();
}
});
AlertDialog alert=alert_bld.create();
setMessage(“您必须选择11名玩家”);
alert.setIcon(R.drawable.icon);
}
}捕获(SQLE异常){
e、 printStackTrace();
}
}
};
/*更多代码*/
}
我应该将什么作为参数传递给构建器?您必须调用
AlertDialog
上的show()
方法,您必须调用AlertDialog
上的show()
方法,该方法显示控件
我认为您缺少显示控件的
alertdialog.show()
方法