1 回答

TA贡献1856条经验 获得超17个赞
在您的医生POJO中再添加一个属性,这将是ID
public class Doctors {
private String id;
private String name;
private String degree;
...
并更新您的构造函数(同时放置您的 setter 和 getter for id)
public Doctors(String id,String name, String specialty, String thumbnail) {
this.name = name;
this.specialty = specialty;
this.thumbnail = thumbnail;
this.id = id;
}
现在,当您获取数据时,获取检索到的数据的密钥,这将是您的医生ID
valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
String name = snapshot.child("name").getValue(String.class);
String specialty = snapshot.child("specialty").getValue(String.class);
String thumbnail = snapshot.child("thumbnail").getValue(String.class);
String id = snapshot.getKey();
Doctors doctor = new Doctors(id,name, specialty,thumbnail);
list.add(doctor);
adapter.notifyDataSetChanged();
}
}
然后在您的通过中,您的意图中ID的额外内容onClickListener()
private View.OnClickListener onItemClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) view.getTag();
int position = viewHolder.getAdapterPosition();
Doctors doctor = list.get(position);
Intent intent = new Intent(getActivity(), DoctorProfile.class);
intent.putExtra("id",doctor.getID();
startActivity(intent);
}
};
添加回答
举报