0

Maybe my question is a beginner one i have this JSON , as a response , I post a "id" and the result is like that , as u can see my response began with square brackets [] and i can't change it

[{
    "id": "1111",
    "nam": "name",
    "namk": "surename",
    "lygn": [{
                "id": "3003",
                "mas": "lurem11",               
                "yeg": "lurem11"
            },
            {
                "id": "5121",
                "mas": "lurem",
                "yeg": "lurem"
            }],
    "lisar": [
        {
            "id": "3",
            "sharh": "lurem22",
            "amal": "lurem22",
            "toz": "1",
            "tb": "1"
        },
        {
            "id": "2113",
            "sharh": "0",
            "amal": "lurem",
            "toz",
            "tb": "1965/06/11"
        }
    ]
}]

this is my request :

@POST("isargaran")
    @Headers({"Content-Type: application/json"})
    Call<List<ForAll>> postbyid(@Body ForAll md);    

and my model class is :

public class ForAll {
    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("nam")
    @Expose
    private String nam;
    @SerializedName("namk")
    @Expose
    private String namk;
    @SerializedName("namp")
    @Expose
    private String namp;
   
    @SerializedName("lygn")
    @Expose
    public List<Ygn> ygn = null;

    @SerializedName("lisar")
    @Expose
    public List<lisar> lisar;

  //getter and setter 

}

and i have "lisar" and "Ygn" class too , So far there is no problem because I get the Response.body and everything well ( i used all of my getters and i showed then in textview ) but the thing is i wanna show them in a recyclerview , i tried and i could only see index 0 , can't see all of them , i mean i can only see (lygn)

{
                "id": "3003",
                "mas": "lurem",               
                "yeg": "lurem"
            }

(and first data for "lisar")

and i don't want to share my adapter And make it crowded here , my question is , HOW CAN I SHOW ALL OFF MY "lygn" AND "lisar" IN RECYCLERVIEW(i have a recycler for each) thanks you guys , ples help me

** i think problem is because of my response starts with []

I'M NEW
  • 63
  • 1
  • 7
  • how are you parsing your response json? – sneharc Oct 28 '20 at 12:56
  • @sneharc ```ForAll result = forAlls.get(position);``` ... ```result.getLisar().get(position).getTb()``` in my adapter sorry if i got you wrong ma'am – I'M NEW Oct 28 '20 at 13:00
  • check the adapter class from these links: https://stackoverflow.com/a/36967003/9752602 https://stackoverflow.com/q/41402581/9752602 – sneharc Oct 28 '20 at 13:18
  • @sneharc It could not help me I have other recyclers in my app that show all the data (exactly what I want , i mean i know how can i use adapter for simple jsons like those jsons in those links) but my problem is with these lists ("lygn" and "lisar")" thank you anyways – I'M NEW Oct 28 '20 at 13:28

2 Answers2

-1

First, you need to separate response

ForAll resource = response.get(0);

Now you need to pass separate data in recycler view Adapter

List<Ygn> lygnData = resource.getygn();
List<lisar> lisarData = resource.getlisar();
Deep Parsania
  • 253
  • 2
  • 12
-1

setup adapter with recyclerview like this,

//Pass your list in to adapter   
var adapter = RecyclerViewAdapter(list)
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = pendingAdapter

Here is your adapater class,

 class RecyclerViewAdapter(
        private val list: List<String>
    ) : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>() {
    
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
            val v = LayoutInflater.from(parent.context).inflate(R.layout.row, parent, false)   // pass your row (.xml) Here
            return ViewHolder(v)
        }
    
        override fun onBindViewHolder(holder: ViewHolder, position: Int) {
            // Bind Your Data Here
        }
    
        override fun getItemCount(): Int {
            return list.size
        }
    
        class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
    }
Ronak Ukani
  • 603
  • 5
  • 20