【问题标题】:BottomSheetDialogFragment inside Fragment problemFragment 内的BottomSheetDialogFragment 问题
【发布时间】:2019-11-25 14:08:18
【问题描述】:

在 Fragment 中显示 BottomSheetDialogFragment 并与特定按钮(如根据下图增加价格)进行交互后,Fragment 消失并按第二张照片显示。

代码:

increase_price.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String coun_cost = shipment_price.getText().toString();

            if (coun_cost.isEmpty()) {
                counter_price = 0;
                counter_price = counter_price + 5;
                requestFocus(shipment_price);
                shipment_price.setText(String.valueOf(counter_price));
            } else {
                counter_price = Integer.valueOf(coun_cost);
                counter_price = counter_price + 5;
                requestFocus(shipment_price);
                shipment_price.setText(String.valueOf(counter_price));
            }
        }
    });

    decrement_price.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String coun_cost = shipment_price.getText().toString();

            if (!coun_cost.isEmpty()) {
                counter_price = Integer.valueOf(coun_cost);
                counter_price = counter_price - 5;
                if (counter_price >= 0) {
                    requestFocus(shipment_price);
                    shipment_price.setText(String.valueOf(counter_price));
                } else {
                    counter_price = 0;
                    requestFocus(shipment_price);
                    shipment_price.setText(String.valueOf(counter_price));
                }
            }
        }
    });

【问题讨论】:

  • 向我们展示您的代码。
  • @JohnJoe 代码已添加。
  • 你能显示整个片段类吗,我不认为上面的代码有任何错误

标签: android-fragments dialog bottom-sheet


【解决方案1】:

我在删除以下代码行后解决了我的问题。

    param = Objects.requireNonNull(getActivity()).getWindow().getAttributes();
    param.width = WindowManager.LayoutParams.MATCH_PARENT;
    param.height = WindowManager.LayoutParams.DIM_AMOUNT_CHANGED;

【讨论】:

    猜你喜欢
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 2018-02-16
    • 1970-01-01
    相关资源
    最近更新 更多