冲刺第七天
昨天任务是完成多条件的查询
今天的任务依旧是完成多条件的查询
困难是查询结果界面的编写
package com.example.tuandui;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.tuandui.entity.Jz;
import java.util.List;
//这是一个RecyclerView.Adapter的子类,用于管理和展示Jz实体类数据的列表视图
//它定义了如何创建每个item的视图(onCreateViewHolder),如何绑定数据到每个item(onBindViewHolder),以及列表项的数量(getItemCount)。
public class JzAdapter extends RecyclerView.Adapter<JzAdapter.JzViewHolder> {
private List<Jz> jzs;
public JzAdapter(List<Jz> jzs) {
this.jzs = jzs;
}
//setData方法用于更新适配器的数据集,并通知数据集有变化,从而刷新RecyclerView的显示。
public void setData(List<Jz> jzs) {
this.jzs.clear();
this.jzs.addAll(jzs);
notifyDataSetChanged();
}
@NonNull
@Override
public JzViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_jzs, parent, false);
return new JzViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull JzViewHolder holder, int position) {
Jz jz = jzs.get(position);
holder.bind(jz);
}
@Override
public int getItemCount() {
return jzs.size();
}
//JzViewHolder类是视图持有者,负责存储item布局中的各个视图引用,并在bind方法中根据传入的Jz对象更新视图内容。
static class JzViewHolder extends RecyclerView.ViewHolder {
TextView txtDonator;
TextView txtLocation;
TextView txtClasses;
public JzViewHolder(@NonNull View itemView) {
super(itemView);
txtDonator = itemView.findViewById(R.id.txt_donator);
txtLocation = itemView.findViewById(R.id.txt_location);
txtClasses = itemView.findViewById(R.id.txt_classes);
}
void bind(Jz jz) {
//先将值定为空,相当于刷新界面
txtDonator.setText("");
txtLocation.setText("");
txtClasses.setText("");
txtDonator.setText(jz.getDonator());
txtLocation.setText(jz.getLocation());
txtClasses.setText(jz.getClasses());
}
}
}
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.tuandui.entity.Jz;
import java.util.List;
//这是一个RecyclerView.Adapter的子类,用于管理和展示Jz实体类数据的列表视图
//它定义了如何创建每个item的视图(onCreateViewHolder),如何绑定数据到每个item(onBindViewHolder),以及列表项的数量(getItemCount)。
public class JzAdapter extends RecyclerView.Adapter<JzAdapter.JzViewHolder> {
private List<Jz> jzs;
public JzAdapter(List<Jz> jzs) {
this.jzs = jzs;
}
//setData方法用于更新适配器的数据集,并通知数据集有变化,从而刷新RecyclerView的显示。
public void setData(List<Jz> jzs) {
this.jzs.clear();
this.jzs.addAll(jzs);
notifyDataSetChanged();
}
@NonNull
@Override
public JzViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_jzs, parent, false);
return new JzViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull JzViewHolder holder, int position) {
Jz jz = jzs.get(position);
holder.bind(jz);
}
@Override
public int getItemCount() {
return jzs.size();
}
//JzViewHolder类是视图持有者,负责存储item布局中的各个视图引用,并在bind方法中根据传入的Jz对象更新视图内容。
static class JzViewHolder extends RecyclerView.ViewHolder {
TextView txtDonator;
TextView txtLocation;
TextView txtClasses;
public JzViewHolder(@NonNull View itemView) {
super(itemView);
txtDonator = itemView.findViewById(R.id.txt_donator);
txtLocation = itemView.findViewById(R.id.txt_location);
txtClasses = itemView.findViewById(R.id.txt_classes);
}
void bind(Jz jz) {
//先将值定为空,相当于刷新界面
txtDonator.setText("");
txtLocation.setText("");
txtClasses.setText("");
txtDonator.setText(jz.getDonator());
txtLocation.setText(jz.getLocation());
txtClasses.setText(jz.getClasses());
}
}
}