我已成功实施材料对话框:
现在,当我在“材料对话框”中进行选择时,我想在片段抽屉中更新标签。 所以我想:简单,只需实现接口,你就会有回调方法。但这些方法从未运行过。
我尝试了一些方法,但它们都不起作用,因为它们永远不会运行。
public class FragmentDrawer extends Fragment implements MaterialDialog.ListCallbackSingleChoice, MaterialListPreference.OnPreferenceClickListener, MaterialDialog.OnShowListener, MaterialDialog.OnClickListener{
(...)
@Override
public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
SnackbarManager.show(
Snackbar.with(getActivity())
.text("Single-line snackbar"));
return false;
}
}
对话:
new MaterialDialog.Builder(getActivity())
.title(R.string.title)
.items(R.array.items)
.itemsCallbackSingleChoice(-1, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
/**
* If you use alwaysCallSingleChoiceCallback(), which is discussed below,
* returning false here won't allow the newly selected radio button to actually be selected.
**/
return true;
}
})
.positiveText(R.string.positive_text)
.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
}
})
.show();
感谢您的帮助!
答案 0 :(得分:1)
public class FragmentDrawer extends Fragment implements MaterialDialog.ListCallbackSingleChoice, MaterialListPreference.OnPreferenceClickListener, MaterialDialog.OnShowListener, MaterialDialog.OnClickListener{
(...)
@Override
public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
SnackbarManager.show(
Snackbar.with(getActivity())
.text("Single-line snackbar"));
return false;
}
}
new MaterialDialog.Builder(getActivity())
.title(R.string.title)
.items(R.array.items)
.itemsCallback(this)
.positiveText(R.string.positive_text)
.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
}
})
.show();