android - How do I pass value from one Activity to another and show it in adapter? -


i have recyclervieweractivity custom adapter inside it. there product categories in recyclerviewer , adapter holds name each category like:

category 1 = "drinks", category 2 - "dairy", category 3 = "pasta". 

when user clicks on "drinks" - new activitydrinks called list view add items category- can add soda, cola.

if clicks on "dairy" - activitydairy opens , can add milk, yogurt...

now try implement indicator of existing items in list , pass adapter.so if there @ least 1 item in activitydrinks - want display image above name of category in adapter (in recyclerviewer activity). user see if has items in category or no.

i added boolean variable checking arraylist in every activity (activitydrinks, activitydairy):

if (arraylist == null) {     return false; } else {     return true; } 

this part works, want display image above the name of category in adapter (adapter holds name of each category + imageview hold indicator) depending of value of variable: if variable = true - display image.

this 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> 

enter image description here

and code checking array list in activitydrinks (using firebase):

      public void ondatachange(datasnapshot datasnapshot) {             (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 use putextras , pass value of variable recyclerviewactivity. don't understand how pass value of variable each item in recyclerview. possible "drinks" true , "diary" - false because there no items in activitydairy. in case in adapter drinks need display image/ indicator , diary - not.

intent should used in passing values 1 activity another.

you can have this:

list<dairy> listofdairy = new arraylist<dairy>(); // add dairy...  intent intent = new intent(this, receivingclass.class); i.putextra("key_dairy", listofdairy); startactivity(intent);  

then on receivingclass, can retrieve one:

list<dairy> dairylist = getintent().getparcelablearraylistextra("key_dairy"); 

if not need list, can pass string/boolean via intent. this:

intent intent = new intent(this, receivingclass.class);     i.putextra("key_has_dairy", true); startactivity(intent); 

then

boolean hasdairy = getintent().getbooleanextra("key_has_dairy"); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -