0

I select properties of a product that I log in from FragmentA in another activity. And I keep the FragmentA data when I close the activity. Then I can successfully send the function found in FragmentA to the function found in FragmentB. But I can not show it here with a RecycleView Adapter. It gives me this error No adapter attached; skipping layout I share my codes FragmentB is name 'MasaAdisyon'

FragmentA:

var ADISYONLISTESI = ArrayList<AdisyonListesiBilgileri>()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
        if(requestCode == 1){
            var gecici = AdisyonListesiBilgileri(
                    data?.extras!!.getDouble("MIKTAR"),
                    data?.extras!!.getDouble("PORSIYON"),
                    data?.extras!!.getSerializable("URUNANABILGILERI") as UrunBilgileri,
                    data?.extras!!.getSerializable("SECILENOZELLIKLER") as ArrayList<secilenOzellikler>,
                    data?.extras!!.getSerializable("OZELLIKLISTESI") as ArrayList<UrunOzellikBilgileri>,
                    0,
                    0,
                    null,
                    null,
                    null
            )
            ADISYONLISTESI.add(gecici)
            var bundle = Bundle()
            bundle.putSerializable("ADISYONLISTESI",ADISYONLISTESI)
            var masaAdisyon = MasaAdisyon()
            masaAdisyon.arguments = bundle
            var fragmentManager = getFragmentManager()
            fragmentManager?.beginTransaction()?.replace(R.id.masaAdisyonFrame, MasaAdisyon())?.commit()
            masaAdisyon.adisyonlariListele()

        }
}

FragmentB

class MasaAdisyon : Fragment() {

var IPADRES : String? = null
var FIYATTIPI : String? = null
var KASATIPI : String? = null
var adapter : MasaAdisyonListesiAdapter? = null
companion object {
    fun newInstance(IPADRES: String?, FIYATTIPI: String?, KASATIPI: String?): MasaAdisyon{
        val fragment = MasaAdisyon()
        var bundle = Bundle()
        bundle.putString("IPADRES",IPADRES)
        bundle.putString("FIYATTIPI",FIYATTIPI)
        bundle.putString("KASATIPI",KASATIPI)
        fragment.arguments = bundle
        return fragment
    }
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                          savedInstanceState: Bundle?): View? {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_masa_adisyon, container, false)
}

var activity : Activity? = null
override fun onAttach(context: Context?) {
    super.onAttach(context)
    activity = context as Activity
}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    IPADRES = arguments?.getString("IPADRES")
    FIYATTIPI = arguments?.getString("FIYATTIPI")
    KASATIPI = arguments?.getString("KASATIPI")

}

var ADISYONLISTESI = ArrayList<AdisyonListesiBilgileri>()
fun adisyonlariListele(){
    var args = arguments
    this.ADISYONLISTESI = args?.getSerializable("ADISYONLISTESI") as ArrayList<AdisyonListesiBilgileri>
    this.adapter = MasaAdisyonListesiAdapter(this.ADISYONLISTESI)
    var layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
    activity?.findViewById<RecyclerView>(R.id.ADISYONLISTESIRECYCLE)?.layoutManager = layoutManager
    activity?.findViewById<RecyclerView>(R.id.ADISYONLISTESIRECYCLE)?.adapter = this.adapter
}}

getItemCount gives me 0. However, the array in FragmentB is not empty. Which way do I have to follow?

476rick
  • 2,764
  • 4
  • 29
  • 49
Degisim
  • 115
  • 11
  • Take a look at this: https://stackoverflow.com/a/45453125/4585226. Add the adapter to the recyclerview: recyclerView.layoutManager = LinearLayoutManager(this, LinearLayout.VERTICAL, false) recyclerView.adapter = obj_adapter – 476rick Jun 05 '18 at 07:24
  • @476rick thanks for your reply. I did not get any results – Degisim Jun 05 '18 at 08:54

1 Answers1

0

As I understand you want to modify fragments RecyclerView content in onActivityResult method. Right?

And in your invocation you are looking for RecyclerView with id R.id.ADISYONLISTESIRECYCLE in your actvity - not in fragment. Guess here is your error:

activity?.findViewById<RecyclerView>(R.id.ADISYONLISTESIRECYCLE)...

May be fragment is not attached to activity at the moment, may be activity just can't find this id. Any way you need to search RecyclerView in fragments view.

Ircover
  • 2,406
  • 2
  • 22
  • 42