I think I'm doing it wrong but this is my situation.
I'm getting json data inside a fragment then process it with Gson to a data class and display it. What I need is to use this data again inside another fragment in a custom spinner adapter which is ready.
As much as I understand it's impossible to pass objects so how can I do this !? I have tried to use bundle and it didn't work
the onResponse method (First fragment)
override fun onResponse(call: Call?, response: Response?) {
val jsonString = response?.body()?.string()
val gson = GsonBuilder().create()
val data = gson.fromJson(jsonString,currancyModel::class.java)
countryData = data
activity?.runOnUiThread {
rootView.recyclerView.adapter = CountryAdapter(data)
}
}
the data class
data class currancyModel(val items: List<Item>)
data class Item(val countray :String,val rate:String)
the getView in the custom spinner adapter inside the second fragment (I need my data here)
override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
val view = inflater.inflate(R.layout.custome_spinner,null)
val img = view.findViewById<View>(R.id.spinner_image) as ImageView
val countary_name = view.findViewById<View>(R.id.spinner_country) as TextView
img.setImageResource(R.drawable.us)
countary_name.setText(country!![p0].countray)
return view
}