RecyclerView not populating, likely a silly adapter problem











up vote
0
down vote

favorite












I used a working RecyclerView as a template for another, but I made some sort of mistake in its implementation and I can't find it. Here is the code that initializes the view:



 mMessageThreadList = new ArrayList<>();       
mRecyclerView = findViewById(R.id.chat_list_recycler_view);


private void initRecyclerView() {
Log.d(TAG, "initRecyclerView Called");

//Initializes and sets up adapter

mAdapter = new ChatListRecyclerViewAdapter(mThreadList);
mRecyclerView.setAdapter(mAdapter);


Query query = mThreadCollection;
query.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
switch (documentChange.getType()) {
case ADDED:
Thread thread = documentChange.getDocument().toObject(Thread.class);
Log.d(TAG, "Last Message: " + thread.getLastMessage().getMessage());

mThreadList.add(thread);
mAdapter.notifyDataSetChanged();

}
}
}
});
}


Note that the print log statement in the SnapshotListener does contain a value when printed so the information is returning from Firebase, it's just not displaying. Which makes me think my problem is with my Adapter/Viewholder:



public class ChatListRecyclerViewAdapter extends RecyclerView.Adapter<ChatListRecyclerViewAdapter.ChatListViewHolder> {

private List<Thread> threadList;

ChatListRecyclerViewAdapter(List<Thread> threadList) {
this.threadList = threadList;
}


@NonNull
@Override
public ChatListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_list_row, parent, false);
return new ChatListViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ChatListViewHolder holder, int position) {

// This method fills fields with data for each list item
Log.d(TAG, "onBindViewholder called");

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM hh:mm a");
final Thread thread = threadList.get(position);
char initial = thread.getPartnerName().charAt(0);
char uppercaseInitial = Character.toUpperCase(initial);

Log.d(TAG, thread.getLastMessage() + " " + thread.getPartnerID());


holder.partnerName.setText(thread.getPartnerName());
holder.authorInitial.setText(uppercaseInitial);
holder.lastMessageText.setText(thread.getLastMessage().getMessage());
holder.lastMessageTime.setText(simpleDateFormat.format(thread.getLastMessage().getTimestamp()));

}

@Override
public int getItemCount() {
return threadList.size();
}

//Viewholder stores the information about the layout and content of each list item, and serves as a template for each item of a RecyclerView


public class ChatListViewHolder extends RecyclerView.ViewHolder {

TextView partnerName;
TextView authorInitial;
TextView lastMessageText;
TextView lastMessageTime;
LinearLayout listTextHolder;

public ChatListViewHolder(View itemView) {
super(itemView);

partnerName = itemView.findViewById(R.id.partner_name);
authorInitial = itemView.findViewById(R.id.partner_initial);
lastMessageText = itemView.findViewById(R.id.last_message);
lastMessageTime = itemView.findViewById(R.id.last_message_time);
listTextHolder = itemView.findViewById(R.id.list_text_holder);

}
}
}


chat_list_row.xml file:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_thread_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/colorPrimaryDark">

<TextView
android:id="@+id/partner_initial"
android:background="@drawable/chat_list_circle"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:text="A"
android:textSize="36sp"
tools:ignore="HardcodedText" />


<TextView
android:id="@+id/last_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:padding="5dp"
android:fontFamily="@font/nunito_extralight"
android:text="@string/sample_time"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

<LinearLayout
android:id="@+id/list_text_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/partner_initial"
android:layout_centerVertical="true"
android:orientation="vertical">

<TextView
android:id="@+id/partner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito"
android:text="@string/sample_name"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="sans" />

<TextView
android:id="@+id/last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito_extralight"
android:gravity="start"
android:text="@string/sample_message"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

</LinearLayout>

</RelativeLayout>


Edit: Layout of the Activity that RecyclerView appears in. I also edit above code to show where the variable is attached to the view:



<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimaryDark"
android:paddingLeft="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="0dp"
android:paddingBottom="0dp"
tools:context="org.andrewedgar.theo.ChatListActivity">

<include
android:id="@+id/chat_list_toolbar"
layout="@layout/toolbar" />


<android.support.v7.widget.RecyclerView
android:id="@+id/chat_list_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chat_list_toolbar" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/new_check_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_person_pin_circle_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>









share|improve this question
























  • You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
    – Hocine B
    Nov 11 at 0:50












  • Could you post your chat_list_row layout please?
    – Aaron
    Nov 11 at 0:52










  • Posted. There is no exception. The information is getting pulled down.
    – aedgar777
    Nov 11 at 1:10






  • 1




    You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
    – Pawel
    Nov 11 at 1:13










  • Code looks normal to me.. any chance that your recycler view is just not visible?
    – Aaron
    Nov 11 at 1:14















up vote
0
down vote

favorite












I used a working RecyclerView as a template for another, but I made some sort of mistake in its implementation and I can't find it. Here is the code that initializes the view:



 mMessageThreadList = new ArrayList<>();       
mRecyclerView = findViewById(R.id.chat_list_recycler_view);


private void initRecyclerView() {
Log.d(TAG, "initRecyclerView Called");

//Initializes and sets up adapter

mAdapter = new ChatListRecyclerViewAdapter(mThreadList);
mRecyclerView.setAdapter(mAdapter);


Query query = mThreadCollection;
query.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
switch (documentChange.getType()) {
case ADDED:
Thread thread = documentChange.getDocument().toObject(Thread.class);
Log.d(TAG, "Last Message: " + thread.getLastMessage().getMessage());

mThreadList.add(thread);
mAdapter.notifyDataSetChanged();

}
}
}
});
}


Note that the print log statement in the SnapshotListener does contain a value when printed so the information is returning from Firebase, it's just not displaying. Which makes me think my problem is with my Adapter/Viewholder:



public class ChatListRecyclerViewAdapter extends RecyclerView.Adapter<ChatListRecyclerViewAdapter.ChatListViewHolder> {

private List<Thread> threadList;

ChatListRecyclerViewAdapter(List<Thread> threadList) {
this.threadList = threadList;
}


@NonNull
@Override
public ChatListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_list_row, parent, false);
return new ChatListViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ChatListViewHolder holder, int position) {

// This method fills fields with data for each list item
Log.d(TAG, "onBindViewholder called");

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM hh:mm a");
final Thread thread = threadList.get(position);
char initial = thread.getPartnerName().charAt(0);
char uppercaseInitial = Character.toUpperCase(initial);

Log.d(TAG, thread.getLastMessage() + " " + thread.getPartnerID());


holder.partnerName.setText(thread.getPartnerName());
holder.authorInitial.setText(uppercaseInitial);
holder.lastMessageText.setText(thread.getLastMessage().getMessage());
holder.lastMessageTime.setText(simpleDateFormat.format(thread.getLastMessage().getTimestamp()));

}

@Override
public int getItemCount() {
return threadList.size();
}

//Viewholder stores the information about the layout and content of each list item, and serves as a template for each item of a RecyclerView


public class ChatListViewHolder extends RecyclerView.ViewHolder {

TextView partnerName;
TextView authorInitial;
TextView lastMessageText;
TextView lastMessageTime;
LinearLayout listTextHolder;

public ChatListViewHolder(View itemView) {
super(itemView);

partnerName = itemView.findViewById(R.id.partner_name);
authorInitial = itemView.findViewById(R.id.partner_initial);
lastMessageText = itemView.findViewById(R.id.last_message);
lastMessageTime = itemView.findViewById(R.id.last_message_time);
listTextHolder = itemView.findViewById(R.id.list_text_holder);

}
}
}


chat_list_row.xml file:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_thread_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/colorPrimaryDark">

<TextView
android:id="@+id/partner_initial"
android:background="@drawable/chat_list_circle"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:text="A"
android:textSize="36sp"
tools:ignore="HardcodedText" />


<TextView
android:id="@+id/last_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:padding="5dp"
android:fontFamily="@font/nunito_extralight"
android:text="@string/sample_time"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

<LinearLayout
android:id="@+id/list_text_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/partner_initial"
android:layout_centerVertical="true"
android:orientation="vertical">

<TextView
android:id="@+id/partner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito"
android:text="@string/sample_name"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="sans" />

<TextView
android:id="@+id/last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito_extralight"
android:gravity="start"
android:text="@string/sample_message"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

</LinearLayout>

</RelativeLayout>


Edit: Layout of the Activity that RecyclerView appears in. I also edit above code to show where the variable is attached to the view:



<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimaryDark"
android:paddingLeft="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="0dp"
android:paddingBottom="0dp"
tools:context="org.andrewedgar.theo.ChatListActivity">

<include
android:id="@+id/chat_list_toolbar"
layout="@layout/toolbar" />


<android.support.v7.widget.RecyclerView
android:id="@+id/chat_list_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chat_list_toolbar" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/new_check_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_person_pin_circle_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>









share|improve this question
























  • You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
    – Hocine B
    Nov 11 at 0:50












  • Could you post your chat_list_row layout please?
    – Aaron
    Nov 11 at 0:52










  • Posted. There is no exception. The information is getting pulled down.
    – aedgar777
    Nov 11 at 1:10






  • 1




    You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
    – Pawel
    Nov 11 at 1:13










  • Code looks normal to me.. any chance that your recycler view is just not visible?
    – Aaron
    Nov 11 at 1:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I used a working RecyclerView as a template for another, but I made some sort of mistake in its implementation and I can't find it. Here is the code that initializes the view:



 mMessageThreadList = new ArrayList<>();       
mRecyclerView = findViewById(R.id.chat_list_recycler_view);


private void initRecyclerView() {
Log.d(TAG, "initRecyclerView Called");

//Initializes and sets up adapter

mAdapter = new ChatListRecyclerViewAdapter(mThreadList);
mRecyclerView.setAdapter(mAdapter);


Query query = mThreadCollection;
query.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
switch (documentChange.getType()) {
case ADDED:
Thread thread = documentChange.getDocument().toObject(Thread.class);
Log.d(TAG, "Last Message: " + thread.getLastMessage().getMessage());

mThreadList.add(thread);
mAdapter.notifyDataSetChanged();

}
}
}
});
}


Note that the print log statement in the SnapshotListener does contain a value when printed so the information is returning from Firebase, it's just not displaying. Which makes me think my problem is with my Adapter/Viewholder:



public class ChatListRecyclerViewAdapter extends RecyclerView.Adapter<ChatListRecyclerViewAdapter.ChatListViewHolder> {

private List<Thread> threadList;

ChatListRecyclerViewAdapter(List<Thread> threadList) {
this.threadList = threadList;
}


@NonNull
@Override
public ChatListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_list_row, parent, false);
return new ChatListViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ChatListViewHolder holder, int position) {

// This method fills fields with data for each list item
Log.d(TAG, "onBindViewholder called");

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM hh:mm a");
final Thread thread = threadList.get(position);
char initial = thread.getPartnerName().charAt(0);
char uppercaseInitial = Character.toUpperCase(initial);

Log.d(TAG, thread.getLastMessage() + " " + thread.getPartnerID());


holder.partnerName.setText(thread.getPartnerName());
holder.authorInitial.setText(uppercaseInitial);
holder.lastMessageText.setText(thread.getLastMessage().getMessage());
holder.lastMessageTime.setText(simpleDateFormat.format(thread.getLastMessage().getTimestamp()));

}

@Override
public int getItemCount() {
return threadList.size();
}

//Viewholder stores the information about the layout and content of each list item, and serves as a template for each item of a RecyclerView


public class ChatListViewHolder extends RecyclerView.ViewHolder {

TextView partnerName;
TextView authorInitial;
TextView lastMessageText;
TextView lastMessageTime;
LinearLayout listTextHolder;

public ChatListViewHolder(View itemView) {
super(itemView);

partnerName = itemView.findViewById(R.id.partner_name);
authorInitial = itemView.findViewById(R.id.partner_initial);
lastMessageText = itemView.findViewById(R.id.last_message);
lastMessageTime = itemView.findViewById(R.id.last_message_time);
listTextHolder = itemView.findViewById(R.id.list_text_holder);

}
}
}


chat_list_row.xml file:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_thread_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/colorPrimaryDark">

<TextView
android:id="@+id/partner_initial"
android:background="@drawable/chat_list_circle"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:text="A"
android:textSize="36sp"
tools:ignore="HardcodedText" />


<TextView
android:id="@+id/last_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:padding="5dp"
android:fontFamily="@font/nunito_extralight"
android:text="@string/sample_time"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

<LinearLayout
android:id="@+id/list_text_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/partner_initial"
android:layout_centerVertical="true"
android:orientation="vertical">

<TextView
android:id="@+id/partner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito"
android:text="@string/sample_name"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="sans" />

<TextView
android:id="@+id/last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito_extralight"
android:gravity="start"
android:text="@string/sample_message"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

</LinearLayout>

</RelativeLayout>


Edit: Layout of the Activity that RecyclerView appears in. I also edit above code to show where the variable is attached to the view:



<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimaryDark"
android:paddingLeft="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="0dp"
android:paddingBottom="0dp"
tools:context="org.andrewedgar.theo.ChatListActivity">

<include
android:id="@+id/chat_list_toolbar"
layout="@layout/toolbar" />


<android.support.v7.widget.RecyclerView
android:id="@+id/chat_list_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chat_list_toolbar" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/new_check_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_person_pin_circle_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>









share|improve this question















I used a working RecyclerView as a template for another, but I made some sort of mistake in its implementation and I can't find it. Here is the code that initializes the view:



 mMessageThreadList = new ArrayList<>();       
mRecyclerView = findViewById(R.id.chat_list_recycler_view);


private void initRecyclerView() {
Log.d(TAG, "initRecyclerView Called");

//Initializes and sets up adapter

mAdapter = new ChatListRecyclerViewAdapter(mThreadList);
mRecyclerView.setAdapter(mAdapter);


Query query = mThreadCollection;
query.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {

for (DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()) {
switch (documentChange.getType()) {
case ADDED:
Thread thread = documentChange.getDocument().toObject(Thread.class);
Log.d(TAG, "Last Message: " + thread.getLastMessage().getMessage());

mThreadList.add(thread);
mAdapter.notifyDataSetChanged();

}
}
}
});
}


Note that the print log statement in the SnapshotListener does contain a value when printed so the information is returning from Firebase, it's just not displaying. Which makes me think my problem is with my Adapter/Viewholder:



public class ChatListRecyclerViewAdapter extends RecyclerView.Adapter<ChatListRecyclerViewAdapter.ChatListViewHolder> {

private List<Thread> threadList;

ChatListRecyclerViewAdapter(List<Thread> threadList) {
this.threadList = threadList;
}


@NonNull
@Override
public ChatListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_list_row, parent, false);
return new ChatListViewHolder(view);

}

@Override
public void onBindViewHolder(@NonNull ChatListViewHolder holder, int position) {

// This method fills fields with data for each list item
Log.d(TAG, "onBindViewholder called");

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM hh:mm a");
final Thread thread = threadList.get(position);
char initial = thread.getPartnerName().charAt(0);
char uppercaseInitial = Character.toUpperCase(initial);

Log.d(TAG, thread.getLastMessage() + " " + thread.getPartnerID());


holder.partnerName.setText(thread.getPartnerName());
holder.authorInitial.setText(uppercaseInitial);
holder.lastMessageText.setText(thread.getLastMessage().getMessage());
holder.lastMessageTime.setText(simpleDateFormat.format(thread.getLastMessage().getTimestamp()));

}

@Override
public int getItemCount() {
return threadList.size();
}

//Viewholder stores the information about the layout and content of each list item, and serves as a template for each item of a RecyclerView


public class ChatListViewHolder extends RecyclerView.ViewHolder {

TextView partnerName;
TextView authorInitial;
TextView lastMessageText;
TextView lastMessageTime;
LinearLayout listTextHolder;

public ChatListViewHolder(View itemView) {
super(itemView);

partnerName = itemView.findViewById(R.id.partner_name);
authorInitial = itemView.findViewById(R.id.partner_initial);
lastMessageText = itemView.findViewById(R.id.last_message);
lastMessageTime = itemView.findViewById(R.id.last_message_time);
listTextHolder = itemView.findViewById(R.id.list_text_holder);

}
}
}


chat_list_row.xml file:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/single_thread_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/colorPrimaryDark">

<TextView
android:id="@+id/partner_initial"
android:background="@drawable/chat_list_circle"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:text="A"
android:textSize="36sp"
tools:ignore="HardcodedText" />


<TextView
android:id="@+id/last_message_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:padding="5dp"
android:fontFamily="@font/nunito_extralight"
android:text="@string/sample_time"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

<LinearLayout
android:id="@+id/list_text_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/partner_initial"
android:layout_centerVertical="true"
android:orientation="vertical">

<TextView
android:id="@+id/partner_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito"
android:text="@string/sample_name"
android:textColor="@color/white"
android:textSize="14sp"
android:textStyle="bold"
android:typeface="sans" />

<TextView
android:id="@+id/last_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="@font/nunito_extralight"
android:gravity="start"
android:text="@string/sample_message"
android:textColor="@android:color/darker_gray"
android:textSize="12sp"
android:typeface="normal" />

</LinearLayout>

</RelativeLayout>


Edit: Layout of the Activity that RecyclerView appears in. I also edit above code to show where the variable is attached to the view:



<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimaryDark"
android:paddingLeft="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="0dp"
android:paddingBottom="0dp"
tools:context="org.andrewedgar.theo.ChatListActivity">

<include
android:id="@+id/chat_list_toolbar"
layout="@layout/toolbar" />


<android.support.v7.widget.RecyclerView
android:id="@+id/chat_list_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chat_list_toolbar" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/new_check_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_person_pin_circle_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>






android android-recyclerview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 18:31









Faysal Ahmed

3,51541129




3,51541129










asked Nov 11 at 0:47









aedgar777

9010




9010












  • You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
    – Hocine B
    Nov 11 at 0:50












  • Could you post your chat_list_row layout please?
    – Aaron
    Nov 11 at 0:52










  • Posted. There is no exception. The information is getting pulled down.
    – aedgar777
    Nov 11 at 1:10






  • 1




    You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
    – Pawel
    Nov 11 at 1:13










  • Code looks normal to me.. any chance that your recycler view is just not visible?
    – Aaron
    Nov 11 at 1:14


















  • You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
    – Hocine B
    Nov 11 at 0:50












  • Could you post your chat_list_row layout please?
    – Aaron
    Nov 11 at 0:52










  • Posted. There is no exception. The information is getting pulled down.
    – aedgar777
    Nov 11 at 1:10






  • 1




    You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
    – Pawel
    Nov 11 at 1:13










  • Code looks normal to me.. any chance that your recycler view is just not visible?
    – Aaron
    Nov 11 at 1:14
















You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
– Hocine B
Nov 11 at 0:50






You should check if FirebaseFirestoreException e is not equal null before doing any operation to gain time
– Hocine B
Nov 11 at 0:50














Could you post your chat_list_row layout please?
– Aaron
Nov 11 at 0:52




Could you post your chat_list_row layout please?
– Aaron
Nov 11 at 0:52












Posted. There is no exception. The information is getting pulled down.
– aedgar777
Nov 11 at 1:10




Posted. There is no exception. The information is getting pulled down.
– aedgar777
Nov 11 at 1:10




1




1




You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
– Pawel
Nov 11 at 1:13




You should rename your custom Thread class, when people see it they usually think about java.lang.Thread which is one of the core classes. Especially since your code sample does not include your imports.
– Pawel
Nov 11 at 1:13












Code looks normal to me.. any chance that your recycler view is just not visible?
– Aaron
Nov 11 at 1:14




Code looks normal to me.. any chance that your recycler view is just not visible?
– Aaron
Nov 11 at 1:14












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Seems like you have missed to add layout manager of RecyclerView. Would you please add this and try again



RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);





share|improve this answer

















  • 1




    This was it. Thank you.
    – aedgar777
    Nov 11 at 18:21










  • Welcome. Happy to help you.
    – Faysal Ahmed
    Nov 11 at 18:27


















up vote
0
down vote













Your recyclerview is not showing any data because the list in adapter is still empty. After fetching data from firebase you are adding to mThreadList, which is still with activity and not adapter. To update the list in adapter you can add a method in adapter class and pass the list to adapter and notifyDataseChanged there.



Activity:



 //after firebase task...
mAdapter.updateData(mThreadList);


Adapter: add new method



void updateData(List<Thread> threadList){
this.threadList = threadList;
notifyDatasetChanged(); //notify adapter that new list is added
}





share|improve this answer





















    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',
    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
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244848%2frecyclerview-not-populating-likely-a-silly-adapter-problem%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    Seems like you have missed to add layout manager of RecyclerView. Would you please add this and try again



    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);





    share|improve this answer

















    • 1




      This was it. Thank you.
      – aedgar777
      Nov 11 at 18:21










    • Welcome. Happy to help you.
      – Faysal Ahmed
      Nov 11 at 18:27















    up vote
    1
    down vote



    accepted










    Seems like you have missed to add layout manager of RecyclerView. Would you please add this and try again



    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);





    share|improve this answer

















    • 1




      This was it. Thank you.
      – aedgar777
      Nov 11 at 18:21










    • Welcome. Happy to help you.
      – Faysal Ahmed
      Nov 11 at 18:27













    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    Seems like you have missed to add layout manager of RecyclerView. Would you please add this and try again



    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);





    share|improve this answer












    Seems like you have missed to add layout manager of RecyclerView. Would you please add this and try again



    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(mLayoutManager);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 11 at 18:18









    Faysal Ahmed

    3,51541129




    3,51541129








    • 1




      This was it. Thank you.
      – aedgar777
      Nov 11 at 18:21










    • Welcome. Happy to help you.
      – Faysal Ahmed
      Nov 11 at 18:27














    • 1




      This was it. Thank you.
      – aedgar777
      Nov 11 at 18:21










    • Welcome. Happy to help you.
      – Faysal Ahmed
      Nov 11 at 18:27








    1




    1




    This was it. Thank you.
    – aedgar777
    Nov 11 at 18:21




    This was it. Thank you.
    – aedgar777
    Nov 11 at 18:21












    Welcome. Happy to help you.
    – Faysal Ahmed
    Nov 11 at 18:27




    Welcome. Happy to help you.
    – Faysal Ahmed
    Nov 11 at 18:27












    up vote
    0
    down vote













    Your recyclerview is not showing any data because the list in adapter is still empty. After fetching data from firebase you are adding to mThreadList, which is still with activity and not adapter. To update the list in adapter you can add a method in adapter class and pass the list to adapter and notifyDataseChanged there.



    Activity:



     //after firebase task...
    mAdapter.updateData(mThreadList);


    Adapter: add new method



    void updateData(List<Thread> threadList){
    this.threadList = threadList;
    notifyDatasetChanged(); //notify adapter that new list is added
    }





    share|improve this answer

























      up vote
      0
      down vote













      Your recyclerview is not showing any data because the list in adapter is still empty. After fetching data from firebase you are adding to mThreadList, which is still with activity and not adapter. To update the list in adapter you can add a method in adapter class and pass the list to adapter and notifyDataseChanged there.



      Activity:



       //after firebase task...
      mAdapter.updateData(mThreadList);


      Adapter: add new method



      void updateData(List<Thread> threadList){
      this.threadList = threadList;
      notifyDatasetChanged(); //notify adapter that new list is added
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Your recyclerview is not showing any data because the list in adapter is still empty. After fetching data from firebase you are adding to mThreadList, which is still with activity and not adapter. To update the list in adapter you can add a method in adapter class and pass the list to adapter and notifyDataseChanged there.



        Activity:



         //after firebase task...
        mAdapter.updateData(mThreadList);


        Adapter: add new method



        void updateData(List<Thread> threadList){
        this.threadList = threadList;
        notifyDatasetChanged(); //notify adapter that new list is added
        }





        share|improve this answer












        Your recyclerview is not showing any data because the list in adapter is still empty. After fetching data from firebase you are adding to mThreadList, which is still with activity and not adapter. To update the list in adapter you can add a method in adapter class and pass the list to adapter and notifyDataseChanged there.



        Activity:



         //after firebase task...
        mAdapter.updateData(mThreadList);


        Adapter: add new method



        void updateData(List<Thread> threadList){
        this.threadList = threadList;
        notifyDatasetChanged(); //notify adapter that new list is added
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 6:15









        ManishPrajapati

        211313




        211313






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244848%2frecyclerview-not-populating-likely-a-silly-adapter-problem%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues