android 2.1中的AlertDialog
我用以下方式创建并显示我的对话框:
showDialog(1); // Logcat say me that mistake is here.
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:{
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SelectLoc)
.setCancelable(true)
.setPositiveButton(R.string.Phone, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (mExternalStorageAvailable)
{
PathOpenFile = Environment.getExternalStorageDirectory().getPath();
FileManagerActivity(Settings.Pref.getString("Path_Open", PathOpenFile), REQUEST_LOAD);
}
else
Toast.makeText(Main.this, R.string.CheckSD , Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.Ftp, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which){
if (Settings.Pref.getBoolean("Ftp_User",false))
{
FtpConnect _FtpConnect = new FtpConnect();
_FtpConnect.Save_Open = FTP_REQUEST_LOAD;
_FtpConnect.execute();
}
else
Toast.makeText(Main.this, R.string.SetPass , Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();
break;
}
在 2.2 中它工作得很好,但在 2.1 中它会导致强制关闭 -
“java.lang.Illegalargument例外: Activity#onCreateDialog 未创建 id 1 的对话框"
为什么会这样?
I create and show my dialog in next way:
showDialog(1); // Logcat say me that mistake is here.
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:{
Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.SelectLoc)
.setCancelable(true)
.setPositiveButton(R.string.Phone, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if (mExternalStorageAvailable)
{
PathOpenFile = Environment.getExternalStorageDirectory().getPath();
FileManagerActivity(Settings.Pref.getString("Path_Open", PathOpenFile), REQUEST_LOAD);
}
else
Toast.makeText(Main.this, R.string.CheckSD , Toast.LENGTH_LONG).show();
}
})
.setNegativeButton(R.string.Ftp, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which){
if (Settings.Pref.getBoolean("Ftp_User",false))
{
FtpConnect _FtpConnect = new FtpConnect();
_FtpConnect.Save_Open = FTP_REQUEST_LOAD;
_FtpConnect.execute();
}
else
Toast.makeText(Main.this, R.string.SetPass , Toast.LENGTH_LONG).show();
}
});
AlertDialog dialog = builder.create();
dialog.show();
break;
}
In 2.2 It works very well, but in 2.1 it causes force close with -
"java.lang.Illegalargumentexeption:
Activity#onCreateDialog did not create
a dialog for id 1"
Why so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果替换
它
就会按预期开始工作。不知道为什么。
If replace
on
It starts work as expected. Dont know why.
我假设这是因为这个
所以这一行
应该是这样的(未经测试,但很确定)
I'm assuming it is because of this
so this line
Should be something like this (untested, but pretty sure)