0

我通过调用包含一些学生数据的 API 来通过 OK-HTTP 请求获得响应,但是我无法从视图寻呼机中的片段和底部表单对话框片段中带有选项卡布局的视图寻呼机发送该数据

public static class AddBottomSheetDialog extends BottomSheetDialogFragment {

    private ViewPager viewPager;
    private TabLayout tabLayout;
    private ImageView closeImage;

    public static AddBottomSheetDialog newInstances(){
        return new AddBottomSheetDialog();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.bottomsheetfinal,container,false);

        tabLayout  = view.findViewById(R.id.tablayout);
        viewPager = view.findViewById(R.id.viewpager);
        closeImage = view.findViewById(R.id.iv_close);
        btnApply = view.findViewById(R.id.filter_btn);

        closeImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getDialog().dismiss();
            }
        });

        btnApply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getDialog().dismiss();
            }
        });

        SampleTestTabsAdapter adapter = new SampleTestTabsAdapter(getChildFragmentManager(),4);
        adapter.addFragment("By\n Course", new SampleCourseWiseFragment());
        adapter.addFragment("By\nStd",new SampleStandardWiseFragment());

        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    }


    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override public void onShow(DialogInterface dialogInterface) {
                BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialogInterface;
                setupFullHeight(bottomSheetDialog);
            }
        });
        return dialog;
    }

    private void setupFullHeight(BottomSheetDialog bottomSheetDialog) {
        FrameLayout bottomSheet = (FrameLayout) bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
        BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
        ViewGroup.LayoutParams layoutParams = bottomSheet.getLayoutParams();

        int windowHeight = getWindowHeight();
        if (layoutParams != null) {
            layoutParams.height = windowHeight;
        }
        bottomSheet.setLayoutParams(layoutParams);
        behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }

    private int getWindowHeight() {
        // Calculate window height for fullscreen use
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.heightPixels-100;
    }
}

现在我编写的片段代码如下所示:

@Override
public void onOkHttpSuccess(int requestId, int statusCode, String response) {
    Log.e(">>>", "" + response);

    if (response == null) {
        return;
    }

    switch (requestId){
        case CODE_STUDENT_STANDARD:
            Log.e("Standards >>", "" + response);
            final Gson studentStandardList = new Gson();
            try {
                modelClassForStandardList = studentStandardList.fromJson(response, ModelClassForStandard.class);
                if (modelClassForStandardList.getStandards() != null
                        && modelClassForStandardList.getStandards().size() > 0) {
                    mALstandard = modelClassForStandardList.getStandards();
                    setCourseStandardListAdapter();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case CODE_INQUIRY_FILTER:
            Log.e("standard wise filter",""+response);
            final Gson standardwisefilter = new Gson();
            try{
                mALinquirydetails = new ArrayList<>();
                modelClassForInquiryDetails = standardwisefilter.fromJson(response,ModelClassForInquiryDetails.class);
                if(modelClassForInquiryDetails.getInquiries()!=null && modelClassForInquiryDetails.getInquiries().size()>0){
                    mALinquirydetails = modelClassForInquiryDetails.getInquiries();
                    MyBottomsheetclicklistner myBottomsheetclicklistner = (MyBottomsheetclicklistner) getActivity();
                    myBottomsheetclicklistner.onReturnValue(mALinquirydetails);
                    Toast.makeText(getActivity(), ""+mALinquirydetails.get(0).getFname(), Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(getActivity(), "Data not found Here According to : "+strSelectedStandardIds, Toast.LENGTH_SHORT).show();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            break;
    }
}

现在我的问题是我在数组列表中获取这些数据,但是按钮如何知道哪种数据来自片段?我们可以控制底部工作表对话框片段或其他活动中的按钮吗?这可以通过android studio中的片段点击应用按钮吗?

4

0 回答 0