我在“回收者”视图中创建了一个“回收者”视图。当我选择内部回收器视图时,会显示一个对话框,我想在该对话框中配置回收器视图。我创建了一个对话框并成功地显示了该对话框。但我不知道如何在对话框中创建回收器视图。请帮帮我。
对话框类
public class RoomDialog extends Dialog {
private EditText etStudentName, etStudentNumber;
private Button btnConfirm, btnCancel;
private Context context;
private CustomDialogClickListener clickListener;
private Retrofit retrofit;
public EditText getEtStudentName() {
return etStudentName;
}
public EditText getEtStudentNumber() {
return etStudentNumber;
}
public Button getBtnConfirm() {
return btnConfirm;
}
public Button getBtnCancel() {
return btnCancel;
}
public RoomDialog(@NonNull Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_room);
etStudentName = findViewById(R.id.et_room_Studentname);
etStudentNumber = findViewById(R.id.et_room_studentNumber);
btnConfirm = findViewById(R.id.btn_room_confrim);
btnCancel = findViewById(R.id.btn_room_cancel);
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
}) ;
btnCancel.setOnClickListener( new View.OnClickListener(){
@Override
public void onClick(View v) {
dismiss();
}
});
}
}
内部回收器视图
public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.CustomViewHolder> {
private Context context;
private ArrayList<RoomData> rooms;
public ArrayList<StudnetInRoomData> students;
private LayoutInflater inflater;
public RoomAdapter(Context context, ArrayList<RoomData> rooms) {
this.context = context;
this.rooms = rooms;
this.inflater = LayoutInflater.from(context);
students = new ArrayList<>();
}
@Override
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
view = inflater.inflate(R.layout.single_room, parent, false);
return new CustomViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
RoomData room = rooms.get(position);
holder.tvRoomNum.setText(String.valueOf(room.roomNum));
}
@Override
public int getItemCount() {
return rooms.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
public TextView tvRoomNum;
public TextView tvRoomTitle;
public CustomViewHolder(View itemView) {
super(itemView);
tvRoomNum = (TextView) itemView.findViewById(R.id.tvRoomNumber);
tvRoomTitle = (TextView) itemView.findViewById(R.id.tv_room_title);
tvRoomNum.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
RoomDialog roomDialog = new RoomDialog(context);
roomDialog.setCanceledOnTouchOutside(true);
roomDialog.setCancelable(true);
roomDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
roomDialog.show();
}
});
}
}
}
暂无答案!
目前还没有任何答案,快来回答吧!