大家好, 林在比賽中工作,當玩家完成了水平而言,我要求球員在警告對話框上的EditText輸入他的名字:驗證了警報對話框
AlertDialog.Builder builder = new Builder(this);
LayoutInflater inflater = getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog_name, null))
// Add action buttons
.setPositiveButton(R.string.alertName, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
playerText = (EditText) ((AlertDialog)dialog).findViewById(R.id.username);
if(playerText.getText() != null && playerText.getText().length() != 0)
Helper.currentPlayer.setName(playerText.getText().toString());
//calculate the score
// save in data base
PlayerDataSource playerDS = new PlayerDataSource(getApplicationContext());
playerDS.open();
Helper.currentPlayer = playerDS.createPlayer(Helper.currentPlayer.getName(), Helper.currentPlayer.getScore(),
Helper.currentPlayer.levels, Helper.currentPlayer.times, LanguageHelper.div);
playerDS.close();
saveStmc();
mainScene.setChildScene(choicesMenu, false, true, true);
}
})
.setTitle("Please Enter Your name")
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
alert = builder.create();
當玩家進入他的名稱並按確定(肯定按鈕)如果名稱存在或不存在,我將檢查數據庫,如果名稱存在:顯示Toast並且不關閉提醒以寫入其他名稱。怎麼做?
對不起Vipin它不工作,我想用戶不能解僱警報,直到輸入有效的名稱 –
可能是你膨脹你查看你需要有你自己的按鈕點擊監聽對話框中的按鈕,如果你的綁定視圖,然後在你的視圖中使用按鈕和 –