0% found this document useful (0 votes)
6 views2 pages

Custom Date Picker Dialog Implementation

The document describes a custom dialog implementation in an Android application. It includes a callback interface for data entry, allowing users to input their name, address, and ID, and select a date. The dialog features buttons for confirming or canceling the input and an option to open a gallery or camera for image selection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Custom Date Picker Dialog Implementation

The document describes a custom dialog implementation in an Android application. It includes a callback interface for data entry, allowing users to input their name, address, and ID, and select a date. The dialog features buttons for confirming or canceling the input and an option to open a gallery or camera for image selection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//.................................................................................

........................................

// interface
private CustomDialogCallback callback;
// The Date use will be selected
private Date SelectedDate;

@Override
public void onAttach(@NonNull Context context) {
[Link](context);
if(context instanceof CustomDialogCallback)
{
callback = (CustomDialogCallback)context;
}
}

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
// To inflate the my custom Dialog
View view =
[Link](getContext()).inflate([Link].dialog_custom,null);
// another way
// @SuppressLint("InflateParams") View view =
getLayoutInflater().inflate([Link].dialog_custom,null);
EditText nameEditText = [Link]([Link]);
EditText addressEditText = [Link]([Link]);
EditText idEditText = [Link]([Link]);
Button dateButton = [Link]([Link]);
ImageView imageView = [Link]([Link]);

SelectedDate = new Date();


[Link](v -> {
DatePickerDialog dialog = new DatePickerDialog(
requireContext(),
(view1, year, month, dayOfMonth) -> {
Calendar calendar = [Link]();
[Link](year, month, dayOfMonth);
SelectedDate = [Link]();
[Link]([Link]());
},
2024, 0, 1
);
[Link]();
});
[Link](v -> {
[Link](getContext(), "‫"هنا ممكن تفتح جاليري أو كاميرا‬,
Toast.LENGTH_SHORT).show();
// ‫ ممكن تستدعي‬intent ‫الختيار صورة‬
});

[Link] builder = new [Link](requireContext());


[Link](view)
.setTitle("‫)"أدخل البيانات‬
.setPositiveButton("OK", (dialog, which) -> {
String name = [Link]().toString();
String address = [Link]().toString();
String id = [Link]().toString();
if (callback != null) {
[Link](name, address, id, SelectedDate);
}
})
.setNegativeButton("Cancel", null);

return [Link]();
}

public interface CustomDialogCallback {


void onDataEntered(String name, String address, String id, Date date);
}
// ................................................................................
..............................................

You might also like