1 回答

TA貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個贊
為什么需要為 Dialog 創(chuàng)建一個新類?
你可以直接從你的活動中做到這一點(diǎn)
AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity)
.setTitle("Confirmar")
.setMessage("Deseja mesmo picar o ponto agora?")
.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (verificarPonto()) {
case 1:
txtHoraEntrada.setText(hora);
ponto.setEntrada(picagem);
return;
...
}
}
})
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
如果由于某種原因你需要創(chuàng)建一個新類,你可以這樣做
public static class FragmentConfirmarPicagem extends DialogFragment {
public DialogInterface.OnClickListener listener;
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle("Confirmar")
.setMessage("Deseja mesmo picar o ponto agora?")
.setPositiveButton("Sim", listener)
.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
}
然后,在你的活動中
FragmentConfirmarPicagem fcp = new FragmentConfirmarPicagem();
fcp.listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (verificarPonto()) {
case 1:
txtHoraEntrada.setText(hora);
ponto.setEntrada(picagem);
return;
...
}
}
};
fcp.show(getSupportFragmentManager(), "Confirmar");
添加回答
舉報