我发现这个库实现了Material Design Dialogs,但逻辑却在某个地方打败了我。我想在选择一个项目后关闭Dialog。
适配器创建如下。
MaterialSimpleListAdapter adapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
@Override
public void onMaterialListItemSelected(int i, MaterialSimpleListItem item) {
long id = item.getId();
switch ((int) id){
case 10 : Email();
}
////I have to dismiss the dialog here, but its created below.
}
});
添加项目
adapter.add(new MaterialSimpleListItem.Builder(this)
.content("Send by Email")
.icon(R.mipmap.ic_mail_gray_48dp)
.backgroundColor(Color.WHITE)
.iconPaddingDp(8)
.id(10)
.build());
然后从适配器创建对话框。
MaterialDialog dialog = new MaterialDialog.Builder(this)
.adapter(adapter, null)
.autoDismiss(true)
.show();
onMaterialListItemSelected 尚未创建 MaterialDialog ,因为它取决于适配器?我该如何解决这个问题?
答案 0 :(得分:1)
显示对话框后,您可以通过
简单地将其关闭dialog.dismiss();
答案 1 :(得分:1)
我建议进行以下更改:
//declare as global the dialog variable
private MaterialDialog dialog;
final MaterialSimpleListAdapter adapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
@Override
public void onMaterialListItemSelected(int index, MaterialSimpleListItem item) {
dialog.dismiss();
}
});
//remove the autoDismiss(true) option, better use the Activity
//context
dialog = new MaterialDialog.Builder(MyActivity.this)
.adapter(adapter, null)
.show();
希望它有所帮助!!!
答案 2 :(得分:0)
dialog.dismiss()
当你需要解雇它时。