Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.a20621646_k2;
- import android.os.Bundle;
- import androidx.fragment.app.DialogFragment;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class ClothesDialogFragment extends DialogFragment {
- public interface OnClothesUpdatedListener {
- void onClothesUpdated(Clothes updatedClothes);
- }
- private Clothes clothes;
- private OnClothesUpdatedListener listener;
- public ClothesDialogFragment(Clothes clothes) {
- this.clothes = clothes;
- }
- public void setListener(OnClothesUpdatedListener listener) {
- this.listener = listener;
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_clothes_dialog, container, false);
- EditText priceEditText = view.findViewById(R.id.priceEditText);
- EditText quantityEditText = view.findViewById(R.id.quantityEditText);
- EditText countryEditText = view.findViewById(R.id.countryEditText);
- Button saveButton = view.findViewById(R.id.saveButton);
- Button cancelButton = view.findViewById(R.id.cancelButton);
- saveButton.setOnClickListener(v -> {
- String newPriceText = priceEditText.getText().toString();
- String newQuantityText = quantityEditText.getText().toString();
- String newCountry = countryEditText.getText().toString();
- if (newPriceText.isEmpty() || newQuantityText.isEmpty() || newCountry.isEmpty()) {
- Toast.makeText(getActivity(), "Please fill in all fields", Toast.LENGTH_SHORT).show();
- Log.d("20621639", "Save button clicked: Some fields are empty");
- } else {
- double newPrice = Double.parseDouble(newPriceText);
- int newQuantity = Integer.parseInt(newQuantityText);
- clothes.setPrice(newPrice);
- clothes.setQuantity(newQuantity);
- clothes.setOriginCountry(newCountry);
- Log.d("20621639", "Save button clicked: Clothes updated");
- dismiss();
- }
- });
- cancelButton.setOnClickListener(v -> dismiss());
- Log.d("20621639", "Cancel button clicked");
- return view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement