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);
}
};
添加回答
舉報