Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate different object with same fields or properties in same recyclerview in android

I am going to develop soccer app, and having following json response.(link)

I have two different class with different names, but with same properties or fields and want to display one same single RecyclerView.

Here I have worldmatch and world having same fields like matchTime, startTime and endTime. I have created pojo class using jsontopojo plugin.

Here is main things, I want to display worldmatch in position 0 and rest of other position world based on club. You can see more details in picture.

enter image description here

enter image description here

This has to be first tab(world) and similarly to other tab like Europe , Asia with respective similar pattern.

Tab1(World)

---------------position 0 (All match)------------------
|
| 930   1100   1130  and so on ( horizontal recyclerview)
|
-------------------------------------------
---------------position 1(Barcelona)------------------
|
| 1130   1230   1330   1430  and so on (  horizontal recyclerview)
|
-------------------------------------------
---------------position 2(Chelsea)------------------
|
| 1300   1400   1500  and so on (  horizontal recyclerview)
|
-------------------------------------------
                     .
                     .
                     .
                   so on
        (vertical recyclerview)

Details explanation picture view:

enter image description here

I have two Recyclerview Adapter, first one is display clubname and pass the respective data to other recycler view which gonna display horizontal view with respetive matchTime.

Populated the Outer Recyclerview position 0, worldmatch data and it reflect all the others, how do i pass the populated both worldmatch and world data in same recyclerview and how to filter out all the tab.

Display matchTime field only from WorldMatch list in position 0 and World list in below 0.(horizontal recyclerview)

Any one have any idea, which is really helpful for me and highly appreciate any idea behind this. Thanks in advance.

like image 883
Horrorgoogle Avatar asked Feb 15 '18 18:02

Horrorgoogle


People also ask

What is the use of ViewHolder in RecyclerView Android?

A RecyclerView. ViewHolder class which caches views associated with the default Preference layouts. A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results.

What is the use of onBindViewHolder in Android?

onBindViewHolder. Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position. Note that unlike android.


3 Answers

You can have the worldMatch as the header of your vertical RecyclerView. You do not really need two different adapters for your RecyclerView in your case. Just add the header in your RecyclerView with the worldMatch class will suffice.

If you want to take a look at how you will be going for adding a header or footer in your RecyclerView, you might take a look at the answer here.

Once you are done with adding the worldMatch as the header of your vertical RecyclerView you will be passing the world data in the adapter of your RecyclerView and show them accordingly.

Let me know if you have any confusions.

like image 185
Reaz Murshed Avatar answered Sep 29 '22 13:09

Reaz Murshed


It is possible. Now you can set the value to another class in response parsing time or setting Adapter time. I also did this way. For example:

   setmatches(List<club.wordlWild> ww){
   List<WorldWild> list = new ArrayList<>();
   for(club.worlWide cw : ww){
     WorldWild w = new WorldWild ();
     w.setMatchTime(cw.getMatchtimie);
     ..
     ...// set values
    list.add(w);
    }
   }

Now you can get add club.worlWide values to WorldWild. If you want change do vise versa.

like image 21
Muthu Avatar answered Sep 29 '22 13:09

Muthu


I did something similar via a parent class to use in the adapter but in your case it might be possible to just have the same class for each match.

like image 24
Lance Toth Avatar answered Sep 29 '22 13:09

Lance Toth