我正在Android上使用DialogFragment
创建自定义AlertDialog.Builder
窗口。关于这个窗口有两种情况:
在第一种情况下,中性按钮自动对焦(这就是我需要的)。在第二种情况下 - 没有任何关注任何按钮。但我还需要关注中性按钮。如何解决这个问题?
public static class OrderDialog extends DialogFragment {
public static OrderDialog newInstance(
int view, String orderId, String data, Boolean status) {
OrderDialog orderInfo = new OrderDialog();
Bundle args = new Bundle();
args.putBoolean("status", status);
args.putInt("view", view);
args.putString("orderid", orderId);
args.putString("data", data);
orderInfo.setArguments(args);
return orderInfo;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
int view = getArguments().getInt("view");
String jsonResult = getArguments().getString("data");
Boolean status = getArguments().getBoolean("status");
String orderId = getArguments().getString("orderid");
Boolean timeStampState = true;
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
OrderObject orderObject;
ApiResponse apiResponse;
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
final View dialogView = inflater.inflate(view, null);
builder.setView(dialogView)
.setNeutralButton(R.string.barcode_rescan,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((ScannerActivity) getActivity())
.retryScan();
}
});
if (status)
builder.setPositiveButton(R.string.order_sucess_button,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((ScannerActivity) getActivity())
.checkInOrder(getOrderIdPost());
}
});
return builder.create();
}
以下是创建此对话框的方法:
DialogFragment getOrderResult;
if (result.first) {
getOrderResult = OrderDialog.newInstance(
R.layout.get_order_result_sucess,
orderId,
result.second,
result.first
);
} else {
getOrderResult = OrderDialog.newInstance(
R.layout.get_order_result_failure,
orderId,
result.second,
result.first
);
}
getOrderResult.show(getFragmentManager(), "order_result_dialog");