Inflate layout having nested RecyclerView that needs to be inflated again
I have an initial recyclerview for comments which I am able to retrieve from the Firebase database by inflating a layout. The inflated layout has another recyclerview for replies on comments. Currently I am able to successfully save the replies for the comments as well in the database. My problem is that how can I retrieve replies for the comments within the (Comments inflated layout) recyclerview. The recyclerview for the replies lies inside the first initial inflated layout for the comments..
This image recyclerview is for the comments
this is the inflated layout for comments with the recyclerview for replies
this is the supposed inflated layout which should be inflated for the replies
Database Structure
Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
firebaseAuth = FirebaseAuth.getInstance();
currentUserID = firebaseAuth.getCurrentUser().getUid();
UserBids = FirebaseDatabase.getInstance().getReference().child("All Bids");
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
CommentsRecyclerview = findViewById(R.id.Comments_recycler_view);
CommentsRecyclerview.setHasFixedSize(true);
CommentsRecyclerview.setNestedScrollingEnabled(false);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
CommentsRecyclerview.setLayoutManager(linearLayoutManager);
@Override
protected void onResume() {
super.onResume();
WorkingDataForDisplayingDetails.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Object userid = dataSnapshot.child("currentUserid").getValue();
if (userid != null) {
postedUserID = userid.toString();
Query query = UserBids.child("Comments").child(PostKey).child(postedUserID);
FirebaseRecyclerOptions<Comments> options = new FirebaseRecyclerOptions.Builder<Comments>()
.setQuery(query, Comments.class)
.build();
final FirebaseRecyclerAdapter<Comments, MyViewHolder> adapter
= new FirebaseRecyclerAdapter<Comments, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final MyViewHolder holder, int position, @NonNull final Comments model) {
UserBids.child(PostKey).child(postedUserID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(model.getCurrentuserid())) {
holder.bidder.setText("Bidder");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
holder.name.setText(model.getUserName());
holder.comment.setText(model.getComment());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile).into(holder.userimg);
holder.reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postKeyForReply = getRef(holder.getAdapterPosition()).getKey();
Log.d(TAG, "onClick: inside reply onclick");
holder.replyCommentInput.setVisibility(View.VISIBLE);
holder.replyCommentSendButton.setVisibility(View.VISIBLE);
holder.replyCommentInput.setFocusableInTouchMode(true);
holder.replyCommentInput.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(holder.replyCommentInput, InputMethodManager.SHOW_FORCED);
}
});
holder.replyCommentSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String checkValidReply = holder.replyCommentInput.getText().toString();
if (TextUtils.isEmpty(checkValidReply)) {
Toast.makeText(AllUsersComments.this, "Please write something", Toast.LENGTH_SHORT).show();
} else {
final String randomKeyForReply = UserBids.push().getKey();
HashMap replyMap = new HashMap();
replyMap.put("currentuserid", currentUserID);
replyMap.put("currentusername", saveFirstNameforReplier);
replyMap.put("reply", checkValidReply);
UserBids.child("Reply").child(postKeyForReply)
.child(currentUserID).child(randomKeyForReply).updateChildren(replyMap)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
Toast.makeText(AllUsersComments.this, "Comment Posted", Toast.LENGTH_SHORT).show();
holder.replyCommentInput.setText("");
SharedPreferences sharedPref =
PreferenceManager
.getDefaultSharedPreferences(AllUsersComments.this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("postkeyReply", postKeyForReply);
editor.putString("currentuserid", currentUserID);
editor.commit();
} else {
Toast.makeText(AllUsersComments.this, "An Error has occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
String givenDateString = model.getDate();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy, HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Bahrain"));
long timeInMilliseconds = 0;
try {
Date mDate = sdf.parse(givenDateString);
timeInMilliseconds = mDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
final CharSequence ch = DateUtils.getRelativeTimeSpanString(timeInMilliseconds, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
holder.commentTime.setText(ch);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_section_individual_row_layout, parent, false);
MyViewHolder viewHolder = new MyViewHolder(view);
return viewHolder;
}
};
CommentsRecyclerview.setAdapter(adapter);
adapter.startListening();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public AppCompatTextView name;
public AppCompatTextView reply;
public AppCompatImageView replyCommentSendButton;
public AppCompatEditText replyCommentInput;
public AppCompatTextView bidder;
public AppCompatTextView comment;
public AppCompatTextView commentTime;
public CircleImageView userimg;
public MyViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.CommentersName);
reply = itemView.findViewById(R.id.ReplyButton);
bidder = itemView.findViewById(R.id.checkBidder);
comment = itemView.findViewById(R.id.CommentersComment);
userimg = itemView.findViewById(R.id.UserImageInComment);
commentTime = itemView.findViewById(R.id.commentTimeAgo);
replyCommentSendButton = itemView.findViewById(R.id.replyCommentButton);
replyCommentInput = itemView.findViewById(R.id.replyCommentInputInReply);
}
}
android firebase firebase-realtime-database android-recyclerview
add a comment |
I have an initial recyclerview for comments which I am able to retrieve from the Firebase database by inflating a layout. The inflated layout has another recyclerview for replies on comments. Currently I am able to successfully save the replies for the comments as well in the database. My problem is that how can I retrieve replies for the comments within the (Comments inflated layout) recyclerview. The recyclerview for the replies lies inside the first initial inflated layout for the comments..
This image recyclerview is for the comments
this is the inflated layout for comments with the recyclerview for replies
this is the supposed inflated layout which should be inflated for the replies
Database Structure
Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
firebaseAuth = FirebaseAuth.getInstance();
currentUserID = firebaseAuth.getCurrentUser().getUid();
UserBids = FirebaseDatabase.getInstance().getReference().child("All Bids");
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
CommentsRecyclerview = findViewById(R.id.Comments_recycler_view);
CommentsRecyclerview.setHasFixedSize(true);
CommentsRecyclerview.setNestedScrollingEnabled(false);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
CommentsRecyclerview.setLayoutManager(linearLayoutManager);
@Override
protected void onResume() {
super.onResume();
WorkingDataForDisplayingDetails.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Object userid = dataSnapshot.child("currentUserid").getValue();
if (userid != null) {
postedUserID = userid.toString();
Query query = UserBids.child("Comments").child(PostKey).child(postedUserID);
FirebaseRecyclerOptions<Comments> options = new FirebaseRecyclerOptions.Builder<Comments>()
.setQuery(query, Comments.class)
.build();
final FirebaseRecyclerAdapter<Comments, MyViewHolder> adapter
= new FirebaseRecyclerAdapter<Comments, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final MyViewHolder holder, int position, @NonNull final Comments model) {
UserBids.child(PostKey).child(postedUserID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(model.getCurrentuserid())) {
holder.bidder.setText("Bidder");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
holder.name.setText(model.getUserName());
holder.comment.setText(model.getComment());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile).into(holder.userimg);
holder.reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postKeyForReply = getRef(holder.getAdapterPosition()).getKey();
Log.d(TAG, "onClick: inside reply onclick");
holder.replyCommentInput.setVisibility(View.VISIBLE);
holder.replyCommentSendButton.setVisibility(View.VISIBLE);
holder.replyCommentInput.setFocusableInTouchMode(true);
holder.replyCommentInput.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(holder.replyCommentInput, InputMethodManager.SHOW_FORCED);
}
});
holder.replyCommentSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String checkValidReply = holder.replyCommentInput.getText().toString();
if (TextUtils.isEmpty(checkValidReply)) {
Toast.makeText(AllUsersComments.this, "Please write something", Toast.LENGTH_SHORT).show();
} else {
final String randomKeyForReply = UserBids.push().getKey();
HashMap replyMap = new HashMap();
replyMap.put("currentuserid", currentUserID);
replyMap.put("currentusername", saveFirstNameforReplier);
replyMap.put("reply", checkValidReply);
UserBids.child("Reply").child(postKeyForReply)
.child(currentUserID).child(randomKeyForReply).updateChildren(replyMap)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
Toast.makeText(AllUsersComments.this, "Comment Posted", Toast.LENGTH_SHORT).show();
holder.replyCommentInput.setText("");
SharedPreferences sharedPref =
PreferenceManager
.getDefaultSharedPreferences(AllUsersComments.this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("postkeyReply", postKeyForReply);
editor.putString("currentuserid", currentUserID);
editor.commit();
} else {
Toast.makeText(AllUsersComments.this, "An Error has occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
String givenDateString = model.getDate();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy, HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Bahrain"));
long timeInMilliseconds = 0;
try {
Date mDate = sdf.parse(givenDateString);
timeInMilliseconds = mDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
final CharSequence ch = DateUtils.getRelativeTimeSpanString(timeInMilliseconds, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
holder.commentTime.setText(ch);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_section_individual_row_layout, parent, false);
MyViewHolder viewHolder = new MyViewHolder(view);
return viewHolder;
}
};
CommentsRecyclerview.setAdapter(adapter);
adapter.startListening();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public AppCompatTextView name;
public AppCompatTextView reply;
public AppCompatImageView replyCommentSendButton;
public AppCompatEditText replyCommentInput;
public AppCompatTextView bidder;
public AppCompatTextView comment;
public AppCompatTextView commentTime;
public CircleImageView userimg;
public MyViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.CommentersName);
reply = itemView.findViewById(R.id.ReplyButton);
bidder = itemView.findViewById(R.id.checkBidder);
comment = itemView.findViewById(R.id.CommentersComment);
userimg = itemView.findViewById(R.id.UserImageInComment);
commentTime = itemView.findViewById(R.id.commentTimeAgo);
replyCommentSendButton = itemView.findViewById(R.id.replyCommentButton);
replyCommentInput = itemView.findViewById(R.id.replyCommentInputInReply);
}
}
android firebase firebase-realtime-database android-recyclerview
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07
add a comment |
I have an initial recyclerview for comments which I am able to retrieve from the Firebase database by inflating a layout. The inflated layout has another recyclerview for replies on comments. Currently I am able to successfully save the replies for the comments as well in the database. My problem is that how can I retrieve replies for the comments within the (Comments inflated layout) recyclerview. The recyclerview for the replies lies inside the first initial inflated layout for the comments..
This image recyclerview is for the comments
this is the inflated layout for comments with the recyclerview for replies
this is the supposed inflated layout which should be inflated for the replies
Database Structure
Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
firebaseAuth = FirebaseAuth.getInstance();
currentUserID = firebaseAuth.getCurrentUser().getUid();
UserBids = FirebaseDatabase.getInstance().getReference().child("All Bids");
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
CommentsRecyclerview = findViewById(R.id.Comments_recycler_view);
CommentsRecyclerview.setHasFixedSize(true);
CommentsRecyclerview.setNestedScrollingEnabled(false);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
CommentsRecyclerview.setLayoutManager(linearLayoutManager);
@Override
protected void onResume() {
super.onResume();
WorkingDataForDisplayingDetails.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Object userid = dataSnapshot.child("currentUserid").getValue();
if (userid != null) {
postedUserID = userid.toString();
Query query = UserBids.child("Comments").child(PostKey).child(postedUserID);
FirebaseRecyclerOptions<Comments> options = new FirebaseRecyclerOptions.Builder<Comments>()
.setQuery(query, Comments.class)
.build();
final FirebaseRecyclerAdapter<Comments, MyViewHolder> adapter
= new FirebaseRecyclerAdapter<Comments, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final MyViewHolder holder, int position, @NonNull final Comments model) {
UserBids.child(PostKey).child(postedUserID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(model.getCurrentuserid())) {
holder.bidder.setText("Bidder");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
holder.name.setText(model.getUserName());
holder.comment.setText(model.getComment());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile).into(holder.userimg);
holder.reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postKeyForReply = getRef(holder.getAdapterPosition()).getKey();
Log.d(TAG, "onClick: inside reply onclick");
holder.replyCommentInput.setVisibility(View.VISIBLE);
holder.replyCommentSendButton.setVisibility(View.VISIBLE);
holder.replyCommentInput.setFocusableInTouchMode(true);
holder.replyCommentInput.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(holder.replyCommentInput, InputMethodManager.SHOW_FORCED);
}
});
holder.replyCommentSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String checkValidReply = holder.replyCommentInput.getText().toString();
if (TextUtils.isEmpty(checkValidReply)) {
Toast.makeText(AllUsersComments.this, "Please write something", Toast.LENGTH_SHORT).show();
} else {
final String randomKeyForReply = UserBids.push().getKey();
HashMap replyMap = new HashMap();
replyMap.put("currentuserid", currentUserID);
replyMap.put("currentusername", saveFirstNameforReplier);
replyMap.put("reply", checkValidReply);
UserBids.child("Reply").child(postKeyForReply)
.child(currentUserID).child(randomKeyForReply).updateChildren(replyMap)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
Toast.makeText(AllUsersComments.this, "Comment Posted", Toast.LENGTH_SHORT).show();
holder.replyCommentInput.setText("");
SharedPreferences sharedPref =
PreferenceManager
.getDefaultSharedPreferences(AllUsersComments.this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("postkeyReply", postKeyForReply);
editor.putString("currentuserid", currentUserID);
editor.commit();
} else {
Toast.makeText(AllUsersComments.this, "An Error has occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
String givenDateString = model.getDate();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy, HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Bahrain"));
long timeInMilliseconds = 0;
try {
Date mDate = sdf.parse(givenDateString);
timeInMilliseconds = mDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
final CharSequence ch = DateUtils.getRelativeTimeSpanString(timeInMilliseconds, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
holder.commentTime.setText(ch);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_section_individual_row_layout, parent, false);
MyViewHolder viewHolder = new MyViewHolder(view);
return viewHolder;
}
};
CommentsRecyclerview.setAdapter(adapter);
adapter.startListening();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public AppCompatTextView name;
public AppCompatTextView reply;
public AppCompatImageView replyCommentSendButton;
public AppCompatEditText replyCommentInput;
public AppCompatTextView bidder;
public AppCompatTextView comment;
public AppCompatTextView commentTime;
public CircleImageView userimg;
public MyViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.CommentersName);
reply = itemView.findViewById(R.id.ReplyButton);
bidder = itemView.findViewById(R.id.checkBidder);
comment = itemView.findViewById(R.id.CommentersComment);
userimg = itemView.findViewById(R.id.UserImageInComment);
commentTime = itemView.findViewById(R.id.commentTimeAgo);
replyCommentSendButton = itemView.findViewById(R.id.replyCommentButton);
replyCommentInput = itemView.findViewById(R.id.replyCommentInputInReply);
}
}
android firebase firebase-realtime-database android-recyclerview
I have an initial recyclerview for comments which I am able to retrieve from the Firebase database by inflating a layout. The inflated layout has another recyclerview for replies on comments. Currently I am able to successfully save the replies for the comments as well in the database. My problem is that how can I retrieve replies for the comments within the (Comments inflated layout) recyclerview. The recyclerview for the replies lies inside the first initial inflated layout for the comments..
This image recyclerview is for the comments
this is the inflated layout for comments with the recyclerview for replies
this is the supposed inflated layout which should be inflated for the replies
Database Structure
Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
firebaseAuth = FirebaseAuth.getInstance();
currentUserID = firebaseAuth.getCurrentUser().getUid();
UserBids = FirebaseDatabase.getInstance().getReference().child("All Bids");
UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
CommentsRecyclerview = findViewById(R.id.Comments_recycler_view);
CommentsRecyclerview.setHasFixedSize(true);
CommentsRecyclerview.setNestedScrollingEnabled(false);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
CommentsRecyclerview.setLayoutManager(linearLayoutManager);
@Override
protected void onResume() {
super.onResume();
WorkingDataForDisplayingDetails.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Object userid = dataSnapshot.child("currentUserid").getValue();
if (userid != null) {
postedUserID = userid.toString();
Query query = UserBids.child("Comments").child(PostKey).child(postedUserID);
FirebaseRecyclerOptions<Comments> options = new FirebaseRecyclerOptions.Builder<Comments>()
.setQuery(query, Comments.class)
.build();
final FirebaseRecyclerAdapter<Comments, MyViewHolder> adapter
= new FirebaseRecyclerAdapter<Comments, MyViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final MyViewHolder holder, int position, @NonNull final Comments model) {
UserBids.child(PostKey).child(postedUserID).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild(model.getCurrentuserid())) {
holder.bidder.setText("Bidder");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
holder.name.setText(model.getUserName());
holder.comment.setText(model.getComment());
Picasso.get().load(model.getImage()).placeholder(R.drawable.profile).into(holder.userimg);
holder.reply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postKeyForReply = getRef(holder.getAdapterPosition()).getKey();
Log.d(TAG, "onClick: inside reply onclick");
holder.replyCommentInput.setVisibility(View.VISIBLE);
holder.replyCommentSendButton.setVisibility(View.VISIBLE);
holder.replyCommentInput.setFocusableInTouchMode(true);
holder.replyCommentInput.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(holder.replyCommentInput, InputMethodManager.SHOW_FORCED);
}
});
holder.replyCommentSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String checkValidReply = holder.replyCommentInput.getText().toString();
if (TextUtils.isEmpty(checkValidReply)) {
Toast.makeText(AllUsersComments.this, "Please write something", Toast.LENGTH_SHORT).show();
} else {
final String randomKeyForReply = UserBids.push().getKey();
HashMap replyMap = new HashMap();
replyMap.put("currentuserid", currentUserID);
replyMap.put("currentusername", saveFirstNameforReplier);
replyMap.put("reply", checkValidReply);
UserBids.child("Reply").child(postKeyForReply)
.child(currentUserID).child(randomKeyForReply).updateChildren(replyMap)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
Toast.makeText(AllUsersComments.this, "Comment Posted", Toast.LENGTH_SHORT).show();
holder.replyCommentInput.setText("");
SharedPreferences sharedPref =
PreferenceManager
.getDefaultSharedPreferences(AllUsersComments.this);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("postkeyReply", postKeyForReply);
editor.putString("currentuserid", currentUserID);
editor.commit();
} else {
Toast.makeText(AllUsersComments.this, "An Error has occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
String givenDateString = model.getDate();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy, HH:mm");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Bahrain"));
long timeInMilliseconds = 0;
try {
Date mDate = sdf.parse(givenDateString);
timeInMilliseconds = mDate.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
final CharSequence ch = DateUtils.getRelativeTimeSpanString(timeInMilliseconds, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
holder.commentTime.setText(ch);
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_section_individual_row_layout, parent, false);
MyViewHolder viewHolder = new MyViewHolder(view);
return viewHolder;
}
};
CommentsRecyclerview.setAdapter(adapter);
adapter.startListening();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
public AppCompatTextView name;
public AppCompatTextView reply;
public AppCompatImageView replyCommentSendButton;
public AppCompatEditText replyCommentInput;
public AppCompatTextView bidder;
public AppCompatTextView comment;
public AppCompatTextView commentTime;
public CircleImageView userimg;
public MyViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.CommentersName);
reply = itemView.findViewById(R.id.ReplyButton);
bidder = itemView.findViewById(R.id.checkBidder);
comment = itemView.findViewById(R.id.CommentersComment);
userimg = itemView.findViewById(R.id.UserImageInComment);
commentTime = itemView.findViewById(R.id.commentTimeAgo);
replyCommentSendButton = itemView.findViewById(R.id.replyCommentButton);
replyCommentInput = itemView.findViewById(R.id.replyCommentInputInReply);
}
}
android firebase firebase-realtime-database android-recyclerview
android firebase firebase-realtime-database android-recyclerview
edited Nov 26 '18 at 11:46
Aniruddh Parihar
2,16911027
2,16911027
asked Nov 22 '18 at 15:00
joe walkerjoe walker
15
15
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07
add a comment |
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433645%2finflate-layout-having-nested-recyclerview-that-needs-to-be-inflated-again%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433645%2finflate-layout-having-nested-recyclerview-that-needs-to-be-inflated-again%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please add your database structure.
– Alex Mamo
Nov 22 '18 at 15:02
@AlexMamo i have added firebase database structure
– joe walker
Nov 22 '18 at 15:07