까다로운 부분이 View
개체를 얻을 수 있었다 ... 답변이 너무 아래를 공유 할 것입니다 발견했습니다. View
이 있으면 확인란의 UI를 업데이트하기 위해 invalidate()
수 있습니다.
public class MyMultiChoiceDialogFragment extends DialogFragment {
private View mView = null;
@Override @NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(title);
builder.setMultiChoiceItems(
cursor,
isCheckedColumn
labelColumn
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which, boolean isChecked) {
// Handle the checkbox de/selection
/*
* The problem is that, despite onClick being called (with the correct parameter values), the
* checkbox ticks were not updating on the UI.
* Solution is to invalidate/redraw the layout so the checkboxes also update visually
*/
mView.invalidate();
mView.forceLayout(); // Following tests, this line is also required.
}
});
AlertDialog dialog = builder.create();
/*
* This seems to be the only way to get the view.
* Save it in an instance variable so we can access it within onClick()
*/
mView = dialog.getListView();
return dialog;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mView = null; // Clean up/prevent memory leak - necessary?
}
}
: 여기
내
DialogFragment
서브 클래스에서 필수입니다