I have RecyclerViewerActivity
with custom adapter inside it. There are product categories in the RecyclerViewer
and the adapter holds name for each category like:
category 1 = "drinks", category 2 - "dairy", category 3 = "pasta".
When user clicks on "drinks" - new ActivityDrinks
called with list view to add items for this category- he can add soda, cola.
If he clicks on "dairy" - ActivityDairy
opens and he can add milk, yogurt...
Now I try to implement some indicator of existing items in the list and pass it to the adapter.So if there is at least one item in ActivityDrinks
- I want to display some image above the name of the category in my adapter (in RecyclerViewer
activity). So the user could see if he has some items in category or no.
I added boolean variable for checking ArrayList in every activity (ActivityDrinks, ActivityDairy):
if (arrayList == null) {
return false;
}
else {
return true;
}
This part works, but now I want to display image above the the name of the category in my adapter (adapter holds name of each category + ImageView
to hold indicator) depending of value of the variable: if variable = true
- display image.
This is my Layout code (for single card of RecyclerView):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ImageBack"
android:background="@drawable/back_standart">
<!--name of Category (like "drinks")-->
<TextView
android:text="text"
android:id="@+id/item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="22dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="35dp"
android:layout_marginRight="8dp" />
<!--desired indicator-->
<ImageView
android:background="@drawable/iclun"
android:id="@+id/badgeView"
android:layout_marginLeft="100dp"
android:textColor="#FFF"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/item_title" />
</RelativeLayout>
And this is my code for checking Array list in ActivityDrinks (Using Firebase):
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snap: dataSnapshot.getChildren()){
Log.e(snap.getKey(),snap.getChildrenCount()+"");
}
if(dataSnapshot.getChildrenCount()>0){
index_badge = true;
My Adapter:
@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
viewHolder.txtViewTitle.setText(itemsData[position].getItem_title());
viewHolder.badge.setImageResource(itemsData[position].getBadge_index());
I tried to use putExtras and pass the value of my variable to RecyclerViewActivity. But I don't really understand how to pass the value of variable to each item in RecyclerView. It is possible that for "Drinks" it will be true and for "Diary" - false because there are no items in the ActivityDairy. In this case in my adapter for Drinks I need to display the image/ indicator and for Diary - not.