本文介绍了日食检测到setOnShowListener执行错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要定我的setOnShowListener()方法prevent对话框的关闭,所以我写这样的事情,
公开对话update_pop_up()
{
最后AlertDialog.Builder建设者=新AlertDialog.Builder(UgJadwal.this);
LayoutInflater吹气= UgJadwal.this.getLayoutInflater();
查看dialogView = inflater.inflate(R.layout.updatepopup,NULL);
builder.setView(dialogView);
builder.setIcon(R.drawable.update);
builder.setTitle(更新计划); builder.setPositiveButton(R.string.update,新DialogInterface.OnClickListener()
{
@覆盖
公共无效的onClick(DialogInterface对话框,INT ID)
{ }
}); builder.setNeutralButton(R.string.retrieve,新DialogInterface.OnClickListener()
{
@覆盖
公共无效的onClick(DialogInterface对话框,INT ID)
{ }
}); builder.setNegativeButton(R.string.cancel,NULL);
返回builder.create(); builder.setOnShowListener(新DialogInterface.OnShowListener()
{
@覆盖
公共无效昂秀(DialogInterface对话)
{
按钮检索= builder.getButton(AlertDialog.BUTTON_NEUTRAL);
retrieve.setOnClickListener(新View.OnClickListener()
{
@覆盖
公共无效的onClick(视图v)
{
//没做什么;
}
});
}
});
}
至少有由食提示两个错误,第一个是关于 setOnShowListener
即说的方法setOnShowListener(新DialogInterface.OnShowListener(){})是未定义类型AlertDialog.Builder,另一种是在 builder.getButton(AlertDialog.BUTTON_NEUTRAL)
即说的方法getButton(INT)是未定义的类型AlertDialog.Builder。我只是想知道为什么它会引发错误监守我有这样做的权利,我认为。每个人都必须想法解决它,谢谢!
[更新!]
谢谢大家的帮助。这是我对 setOnShowListener最后一个方法()
dialog.setOnShowListener(新DialogInterface.OnShowListener()
{
@覆盖
公共无效昂秀(DialogInterface对话)
{
按钮检索=((AlertDialog)对话框).getButton(AlertDialog.BUTTON_NEUTRAL);
retrieve.setOnClickListener(新View.OnClickListener()
{
@覆盖
公共无效的onClick(视图v)
{
datasource.opentoread();
的String [] =哈日datasource.fetchDaily(ids.getText()的toString());
datasource.close();
day.setText(将String.valueOf(哈日[0]));
subject.setText(将String.valueOf(哈日[1]));
time.setText(将String.valueOf(哈利[2]));
location.setText(将String.valueOf(哈日[3]));
lecture.setText(将String.valueOf(哈日[4]));
Toast.makeText(getApplicationContext(),检索成功,Toast.LENGTH_LONG).show();
}
});
}
});
返回对话框;
解决方案
There are two reasons why you'll get an error with this:
builder.setNegativeButton(R.string.cancel, null);
return builder.create();
builder.setOnShowListener(new DialogInterface.OnShowListener() ...
- You will never reach any code after calling
return
. setOnShowListener()
is a method in AlertDialog, not AlertDialog.Builder.
This is the same problem, getButton()
is a method in AlertDialog, not AlertDialog.Builder.
Try something like this:
...
builder.setNegativeButton(R.string.cancel, null);
final AlertDialog dlg = builder.create();
dlg.setOnShowListener(new DialogInterface.OnShowListener()
{
@Override
public void onShow(DialogInterface dialog)
{
Button retrieve = dlg.getButton(AlertDialog.BUTTON_NEUTRAL);
// Changed this ^^^
retrieve.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
//do nothing;
}
});
}
});
return dlg;
这篇关于日食检测到setOnShowListener执行错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!