Muhammad Hassan Niazi Muhammad Hassan Niazi - 1 month ago 20x
Android Question

Update FirebaseUI FirebaseRecyclerView Child on user click

I am starting with the Firebase Database. I have made a small Task Tracker application in which I am able to push items to DB. I am using Firebase UI and FriebaseRecyclerView.

The issue is I am unable to update childs on item clicks, from the firebaseRecyclerView. Below is the code for my view holder. But on checkbox clicks my DB is not updated as expected.

public static class TaskViewHolder extends RecyclerView.ViewHolder{
TextView title,description;
CheckBox checkBox;
FirebaseAuth mAuth;
FirebaseUser firebaseUser;
public TaskViewHolder(View v) {
title = (TextView) v.findViewById(;
description= (TextView) v.findViewById(;
checkBox = (CheckBox) v.findViewById(;

mAuth = FirebaseAuth.getInstance();
firebaseUser = mAuth.getCurrentUser();
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RecyclerView recyclerView = (RecyclerView) v.findViewById(;
final FirebaseRecyclerAdapter firebaseRecyclerAdapter = (FirebaseRecyclerAdapter) recyclerView.getAdapter();
if(checkBox.isChecked()) {
SpannableString content = new SpannableString(title.getText());
content.setSpan(new StrikethroughSpan(), 0, content.length(), 0);
content = new SpannableString(description.getText());
content.setSpan(new StrikethroughSpan(), 0, content.length(), 0);

} }

Also Below is my adapter code

final FirebaseRecyclerAdapter<UnitTask,TaskViewHolder> adapter =
new FirebaseRecyclerAdapter<UnitTask, TaskViewHolder>(UnitTask.class,R.layout.task,TaskViewHolder.class,userRef) {
protected void populateViewHolder(TaskViewHolder viewHolder, UnitTask model, int position) {
mAuth = FirebaseAuth.getInstance();
firebaseUser = mAuth.getCurrentUser();


My UnitTask class

public class UnitTask {

public String title;
public String description;
boolean completed;

public UnitTask(String title, String description, boolean completed) {
this.title = title;
this.description = description;
this.completed = completed;

public String getTitle() {
return title;

public void setTitle(String title) {
this.title = title;

public String getDescription() {
return description;

public void setDescription(String description) {
this.description = description;

public boolean isCompleted() {
return completed;

public void setCompleted(boolean completed) {
this.completed = completed;

public UnitTask() {
// Do Nothing


Any help will be much appreciated. Also I am just starting with android so do expect of me to make silly mistakes.


hwd hwd

A work around to get your purpose is:

1) when user check on an item, let push a "special value" to firebase db.

2) In FirebaseRecyclerAdapter#populateViewHolder:if item has "special value", change the layout


Try the example from google:

Let see the implementation of Star button.

in you will find:

// Determine if the current user has liked this post and set UI accordingly
if (model.stars.containsKey(getUid())) {
} else {

// Bind Post to ViewHolder, setting OnClickListener for the star button
viewHolder.bindToPost(model, new View.OnClickListener() {
    public void onClick(View starView) {
        // Need to write to both places the post is stored
        DatabaseReference globalPostRef = mDatabase.child("posts").child(postRef.getKey());
        DatabaseReference userPostRef = mDatabase.child("user-posts").child(model.uid).child(postRef.getKey());

        // Run two transactions