Android Studio 从适配器模型类打开片段

9cbw7uwe  于 2023-01-14  发布在  Android
关注(0)|答案(1)|浏览(130)

我正在创建应用程序,我实现了一个BottomSheetDialogFragment从其他片段内部打开,这项工作很好。
但是现在我希望从我的适配器类打开相同的BottomSheetDialogFragment,该适配器类扩展了FirebaseRecyclerAdapter,但没有获得如何从那里打开的方法。
下面是我的适配器类代码:

public class updateRoomAdapter extends FirebaseRecyclerAdapter<model,updateRoomAdapter.myViewHolder> {

    public updateRoomAdapter(@NonNull FirebaseRecyclerOptions<model> options) {
        super(options);
    }

    @Override
    protected void onBindViewHolder(@NonNull myViewHolder holder,final int position, @NonNull model model) {
        holder.id.setText("Room Id:"+model.getRoomId());
        holder.description.setText("Description: "+model.getDescription());
        holder.ac.setText("AC: "+model.getAC());
        holder.rent.setText("Rent: "+model.getRent());
        holder.nob.setText("No.of Beds: "+model.getNumber_of_beds());
        Glide.with(holder.img.getContext()).load(model.getImageUrl()).into(holder.img);
        holder.edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateRoomFragment updateRoomFragment=new UpdateRoomFragment();
                updateRoomFragment.show(getSupportFragmentManager(),updateRoomFragment.getTag());//this line showing error because getSupportFragmentManager() cannot be use here
            }
        });

    }

    @NonNull
    @Override
    public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.updatesinglerow,parent,false);
        return new updateRoomAdapter.myViewHolder(view);
    }

    class myViewHolder extends RecyclerView.ViewHolder {
        CircleImageView img;
        ImageView edit;
        TextView id,description,rent,ac,nob;
        public myViewHolder(@NonNull View itemView) {
            super(itemView);
            img=(CircleImageView) itemView.findViewById(R.id.img1);
            id=(TextView) itemView.findViewById(R.id.nametext);
            description=(TextView) itemView.findViewById(R.id.coursetext);
            rent=(TextView) itemView.findViewById(R.id.rent);
            ac=(TextView) itemView.findViewById(R.id.ac);
            nob=(TextView) itemView.findViewById(R.id.bed);
            edit=(ImageView)itemView.findViewById(R.id.imageView2);

        }
    }
}

如何解决这一问题?

vjhs03f7

vjhs03f71#

嗨RIZWAN ALI请使用此代码

val updateRoomFragment = CreateEventBottomsheet()
            updateRoomFragment.show(
                (viewHolder.itemView.context as AppCompatActivity).supportFragmentManager,
                updateRoomFragment.getTag()
            )

相关问题