Я пытался отправить значение через намерение, но в моем приложении происходил сбой. Итак, я пытаюсь проверить значение в отладчике, и оно показывает ноль. Вот изображение.
Как видите, на нем показаны userId = "null"
и profilephotoURl ="null"
. Почему это происходит?
А вот образ базы данных.
Вот Код
ProfileInfo.class
public class ProfileInfo {
String userName, profilePhotoUrl, phoneNumber, userId;
public ProfileInfo() {}
public ProfileInfo(String userName, String profilePhotoUrl, String phoneNumber, String userId) {
this.userName = userName;
this.profilePhotoUrl = profilePhotoUrl;
this.phoneNumber = phoneNumber;
this.userId = userId;
}
public ProfileInfo(String userName, String phoneNumber) {
this.userName = userName;
this.phoneNumber = phoneNumber;
}
public String getUserId() {
return userId;
}
public String getPhoneNumber() {
return phoneNumber;
}
public String getUserName() {
return userName;
}
public String getProfilePhotoUrl() {
return profilePhotoUrl;
}
UserAdapter.class
public class UsersAdapter extends RecyclerView.Adapter<UsersAdapter.ViewHolder> {
private ArrayList<ProfileInfo> minfo;
public static final String USER_ID = "userid";
Context context;
public UsersAdapter(Context context, ArrayList<ProfileInfo> minfo) {
this.context = context;
this.minfo = minfo;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_item, parent, false);
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(lp);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
final ProfileInfo profileInfo = minfo.get(position);
holder.username.setText(profileInfo.getUserName());
holder.phoneNumber.setText(profileInfo.getPhoneNumber());
holder.id.setText(profileInfo.getUserId());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MessageLayout.class);
intent.putExtra(USER_ID, profileInfo.getUserId());
Log.d("UserID:", profileInfo.getUserId());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return minfo.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView username;
TextView phoneNumber, id;
CircleImageView profileImage;
RelativeLayout relativeLayout;
ViewHolder(@NonNull View itemView) {
super(itemView);
username = itemView.findViewById(R.id.user);
phoneNumber = itemView.findViewById(R.id.phone);
id = itemView.findViewById(R.id.id);
profileImage = itemView.findViewById(R.id.circleProfileImage);
relativeLayout = itemView.findViewById(R.id.relativeLayout);
}
}
}
MessageLayout.class
public class MessageLayout extends AppCompatActivity {
FirebaseUser currentUser;
DatabaseReference db, chatDb;
EditText message;
ImageButton sendMessage;
TextView username;
CircleImageView profileImage;
String recieverId, messageText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_layout);
message = findViewById(R.id.editTextMessage);
sendMessage = findViewById(R.id.sendMessage);
username = findViewById(R.id.displayUsername);
profileImage = findViewById(R.id.circledp);
currentUser = FirebaseAuth.getInstance().getCurrentUser();
Intent intent = getIntent();
recieverId = intent.getStringExtra(UsersAdapter.USER_ID);
db = FirebaseDatabase.getInstance().getReference().child("UserInfo").child(recieverId);
chatDb = FirebaseDatabase.getInstance().getReference().child("Chats");
db.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
ProfileInfo info = dataSnapshot.getValue(ProfileInfo.class);
username.setText(info.getUserName());
Glide.with(MessageLayout.this).load(info.getProfilePhotoUrl()).into(profileImage);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}