如何从Recyclerview Adapter中实现对话框片段?

时间:2018-08-04 05:30:04

标签: android android-recyclerview android-dialogfragment

此处无法解决show方法。如何解决。我想从回收视图调用DialogFragmnent。如何通过Recyclerview适配器解析此show方法。我想在单击回收视图的项目列表期间调用此对话框片段。这怎么可能?

public class AppointmentServiceListAdapter extends RecyclerView.Adapter<AppointmentServiceListAdapter.ViewHolder>
    {

        Context mContext;
        SessionManager mSessionManager;
        ArrayList<AppointServiceList> appointArrayList;
        ArrayList<AppointServiceDetails> appointservicedetailsArrayList;
        AppointmentServiceDetailsAdapter appointmentServiceDetailsAdapter;

        public AppointmentServiceListAdapter(Context mContext,ArrayList<AppointServiceList> appointArrayList,ArrayList<AppointServiceDetails> appointservicedetailsArrayList)
        {
            this.mContext = mContext;
            this.appointArrayList = appointArrayList;
            mSessionManager= new SessionManager(mContext);
            this.appointservicedetailsArrayList = appointservicedetailsArrayList;
            appointmentServiceDetailsAdapter = new AppointmentServiceDetailsAdapter(mContext,appointservicedetailsArrayList);
        }

        @NonNull
        @Override
        public AppointmentServiceListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
        {
            LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view               = inflater.inflate(R.layout.item_my_appointmentlist,parent,false);
            AppointmentServiceListAdapter.ViewHolder viewHolder = new AppointmentServiceListAdapter.ViewHolder(view);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull ViewHolder holder, final int position)
        {
                holder.bookingDate.setText(appointArrayList.get(position).getDate());
                holder.bookingEmp.setText(appointArrayList.get(position).getEmpName());
                holder.bookingSlot.setText(appointArrayList.get(position).getSlot());
                holder.rv_appoint_servicelist.setLayoutManager(new LinearLayoutManager(mContext));
                holder.rv_appoint_servicelist.setAdapter(appointmentServiceDetailsAdapter);
                holder.lin_intent.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v)
                    {
                        FragmentManager mfFragmentManager = ((Activity)mContext).getFragmentManager();
                        AppointmentBookingDialogFragment appointmentBookingDialogFragment = new AppointmentBookingDialogFragment(mContext,position);
                        appointmentBookingDialogFragment.show(mfFragmentManager,"appointmentdialog");
                    }
                });



                appointmentServiceDetailsAdapter.notifyDataSetChanged();

        }

        @Override
        public int getItemCount()
        {
            return appointArrayList.size();
        }

        public class ViewHolder extends RecyclerView.ViewHolder
        {
            TextView bookingDate,bookingSlot,bookingEmp;
            RecyclerView rv_appoint_servicelist;
            LinearLayout lin_intent;

            public ViewHolder(View itemView)
            {
                super(itemView);
                bookingDate            = (TextView)itemView.findViewById(R.id.bookingDate);
                bookingSlot            = (TextView)itemView.findViewById(R.id.bookingSlot );
                bookingEmp             = (TextView)itemView.findViewById(R.id.bookingEmp);
                rv_appoint_servicelist = (RecyclerView)itemView.findViewById(R.id.rv_appoint_servicelist);
                lin_intent             = (LinearLayout)itemView.findViewById(R.id.lin_intent);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

您的活动似乎正在扩展<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <h3 id="work">Work</h3> <div class="gl_content"> <button class="call_modal" style="cursor:pointer;">SAS Consult and Support</button> <div class="modal"> <div class="modal_close close"></div> <div class="modal_main"> <img src="https://images.pexels.com/photos/34950/pexels-photo.jpg?auto=compress&cs=tinysrgb&h=350" class="close" style="margin-top:13px;left:96%;position:fixed;"> <div class="content"> <p></p> </div> </div> </div> </div> <div class="content"> <button class="call_modal" style="cursor:pointer;">Global Reporting Infrastructure Project (GRIP)</button> <div class="modal"> <div class="modal_close close"></div> <div class="modal_main"> <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTQxuLL7OoxpB8Eju7xawRbmtMl855M2e09m1-_30NDM8i_m2vr" class="close" style="margin-top:13px;left:96%;position:fixed;"> <div class="content"> <p><strong>Global Reporting Infrastructure Project (GRIP)</strong> is a key global initiative and is aimed at delivering a set of standard reports with standard metrics, definitions and templates across RBWM products Origination, Portfolio Management, Profitability and RWAs by providing a global platform for Risk data aggregation and reporting. RBWM Risk has historically lacked Group level risk aggregation and reporting capability and relied upon end user computing to produce executive reporting to drive risk management and decision making. Numerous inconsistencies relating to Key Performance Indicators (KPI) captured, business definitions used, calculations performed and report formats utilized are inherent with this method of reporting. RBWM Risk management desires a system that will provide more metrics and KPIs to drive better decision making and analysis.</p> </div> </div> </div> </div>,而您的AppCompatActivityAppointmentBookingDialogFragment的子类

将此代码替换为下面的一个android.support.v4.app.DialogFragment,并确保您的适配器具有正确的导入FragmentManager mfFragmentManager = ((Activity)mContext).getFragmentManager();而不是正确的导入import android.support.v4.app.FragmentManager

android.app.FragmentManager

供您参考,如下所示修改了您的代码

FragmentManager mfFragmentManager = ((AppCompatActivity)mContext).getSupportFragmentManager();