Firebase 실시간 데이터베이스의 모든 사용자 데이터를 Recycler View에서 검색하는 애플리케이션을 만들었습니다. 여기에는 이름, 생년월일, 직업 등과 같은 데이터가 있습니다. 클릭하면 해당 특정 사용자의 모든 세부 정보를 표시하는 리사이클 러 뷰에 button을 추가했습니다. 여러 명의 사용자가 있지만 해당 button을 클릭하면 모든 프로필에 한 명의 사용자 데이터 만 표시됩니다.
위의 데이터베이스 스냅 샷과 같은 사용자가 더 있습니다.
내 리사이클 러 뷰 어댑터입니다.
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
Button button;
Context context;
private List<User> MainImageUploadInfoList;
RecyclerViewAdapter(Context context, List<User> TempList) {
this.MainImageUploadInfoList = TempList;
this.context = context;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
User user = MainImageUploadInfoList.get(position);
holder.FirstNameTextView.setText(user.getFirst_name()+" "+user.getLast_name());
holder.DateTextView.setText(user.getDate());
holder.HeightTextView.setText(user.getHeight());
holder.EducationTextView.setText(user.getHighest_education());
holder.OccupationTextView.setText(user.getOccupation());
holder.UserIDTextView.setText(user.getUser_id());
holder.ViewProfile.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ResourceType")
@Override
public void onClick(View v) {
Intent it=new Intent(v.getContext(),ViewProfile.class);
context.startActivity(it);
}
});
}
@Override
public int getItemCount() {
return MainImageUploadInfoList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView FirstNameTextView;
//public TextView LastNameTextView;
public TextView DateTextView;
public TextView HeightTextView;
public TextView EducationTextView;
public TextView OccupationTextView;
public TextView UserIDTextView;
public Button ViewProfile;
public ViewHolder(@NonNull View itemView) {
super(itemView);
FirstNameTextView = (TextView) itemView.findViewById(R.id.textView1);
DateTextView=(TextView)itemView.findViewById(R.id.textView3);
HeightTextView=(TextView)itemView.findViewById(R.id.textView4);
EducationTextView=(TextView)itemView.findViewById(R.id.textView5);
OccupationTextView=(TextView)itemView.findViewById(R.id.textView6);
UserIDTextView=(TextView)itemView.findViewById(R.id.textView7);
ViewProfile=(Button)itemView.findViewById(R.id.viewProfile);
}
}}
다음은 내 ViewProfile 코드입니다.
public class ViewProfile extends AppCompatActivity {
ImageView imageView;
TextView tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,tv16;
FirebaseUser mAuth;
FirebaseDatabase database;
DatabaseReference reference;
public static final String Firebase_Server_URL = "https://baghbanshadi-25553.firebaseio.com/User/";
Firebase firebase;
public static final String Database_Path = "User";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_profile);
imageView=(ImageView)findViewById(R.id.imageView4);
tv1=(TextView)findViewById(R.id.textView14);
tv2=(TextView)findViewById(R.id.textView15);
tv3=(TextView)findViewById(R.id.textView16);
tv4=(TextView)findViewById(R.id.textView17);
tv5=(TextView)findViewById(R.id.textView18);
tv6=(TextView)findViewById(R.id.textView19);
tv7=(TextView)findViewById(R.id.textView20);
tv8=(TextView)findViewById(R.id.textView21);
tv9=(TextView)findViewById(R.id.textView22);
tv10=(TextView)findViewById(R.id.textView23);
tv11=(TextView)findViewById(R.id.textView24);
tv12=(TextView)findViewById(R.id.textView25);
tv13=(TextView)findViewById(R.id.textView26);
tv14=(TextView)findViewById(R.id.textView27);
tv15=(TextView)findViewById(R.id.textView28);
tv16=(TextView)findViewById(R.id.textView29);
firebase = new Firebase(Firebase_Server_URL);
reference = FirebaseDatabase.getInstance().getReference().child(Database_Path);
reference.child(mAuth.getUid());
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
User user = dataSnapshot.getValue(User.class);
tv1.setText(user.getFirst_name());
tv2.setText(user.getLast_name());
tv3.setText(user.getLast_name());
tv4.setText(user.getHeight());
tv5.setText(user.getCity_state());
tv6.setText(user.getHobbies());
tv7.setText(user.getHighest_education());
tv8.setText(user.getOccupation());
tv9.setText(user.getIncome());
tv10.setText(user.getMarital_status());
tv11.setText(user.getFamily_members());
tv12.setText(user.getFathers_name());
tv13.setText(user.getMothers_name());
tv14.setText(user.getFathers_occupation());
tv15.setText(user.getMothers_occupation());
tv16.setText(user.getSiblings_names());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}}
이 문제를 해결하도록 도와주세요.