Android的:不能更改文本出现在AlertDialog [英] Android: Can not change the text appears in AlertDialog

查看:227
本文介绍了Android的:不能更改文本出现在AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我遇到一个很奇怪的问题。在我的游戏,我创建AlertDialog向用户显示下一级挑战当一个人成功了。因此,相应的code是这个样子。当游戏成功的ShowDialog(R.id.display_success)被调用并执行以下code。

所以,我期待在每次调用执行此code。然而;游戏执行一次,并表示在每一个其他执行相同AlertDialog。我的意思是,像创建后的第一个未创建实例和第一个实例用于所有的时间。我希望我能描述我的问题。

 情况下R.id.display_success:
       updateGameSettings();
       消息= formatLevel()
       + formatMission();
       返回新AlertDialog.Builder(本)
       .setIcon(R.drawable.smiley_happy)
       .setTitle(R.string.dialog_success)
       .setMessage(消息)
       .setPositiveButton(R.string.alert_dialog_newgame,新DialogInterface.OnClickListener(){
               公共无效的onClick(DialogInterface对话,诠释whichButton){
                       startANewGame();
               }
       })
       .setNegativeButton(R.string.exit,新DialogInterface.OnClickListener(){
               公共无效的onClick(DialogInterface对话,诠释whichButton){
                     完();
               }
       })
       。创建();


在prepareDialog方法

解决方案

时,当所示的对话框调用。所以,最好是通过重写此方法来改变文本或其他功能。

Today I faced a very weird problem. In my game I create AlertDialog to show the user next level challenges when one is succeeded. So, the corresponding code is like this. when the game is succeeded showDialog(R.id.display_success) is called and the following code is executed.

So, I am expecting to execute this code in every call. However; the game is executing only once and showing the same AlertDialog in every other execution. I mean, like the instance is not created after the first one is created and the first instance is used all the time. I hope I was able to describe my problem.

case R.id.display_success:           
       updateGameSettings();
       message = formatLevel()
       + formatMission();
       return new AlertDialog.Builder(this)
       .setIcon(R.drawable.smiley_happy)
       .setTitle(R.string.dialog_success)
       .setMessage(message)
       .setPositiveButton(R.string.alert_dialog_newgame, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog,     int whichButton) {
                       startANewGame();
               }
       })
       .setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {
                     finish();
               }
       })
       .create();

解决方案

onPrepareDialog method is called when the dialog is shown. So, it is better to change the text or other features by overriding this method.

这篇关于Android的:不能更改文本出现在AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆