Android 片段之间的数据传输

Android 片段之间的数据传输,android,android-fragments,Android,Android Fragments,我正在开发一个餐厅项目。我有个问题。现在,我将告诉您在产品选择过程中发生的事件 **该应用程序由两个片段组成。活动名称为“MasaDetay”。FragmentOne的名字是“MasaUrunler”,FragmentTwo的名字是“MasaAdisyon”** 在“马索伦勒”片段中的动作 我从数据库中截取产品,并在屏幕上列出它们,这要归功于一个RecycleView 我打印列出的产品,并在其他活动中选择这些产品的数量、部分和属性 我在onActivityResult函数中获取所有数据 我将数组

我正在开发一个餐厅项目。我有个问题。现在,我将告诉您在产品选择过程中发生的事件

**该应用程序由两个片段组成。活动名称为“MasaDetay”。FragmentOne的名字是“MasaUrunler”,FragmentTwo的名字是“MasaAdisyon”**

在“马索伦勒”片段中的动作

  • 我从数据库中截取产品,并在屏幕上列出它们,这要归功于一个RecycleView
  • 我打印列出的产品,并在其他活动中选择这些产品的数量、部分和属性
  • 我在onActivityResult函数中获取所有数据
  • 我将数组中的数据发送到另一个片段中
  • 在“MasaAdisyon”片段中,发生以下事件

  • 我正在onCreateView中执行LayoutManager事件,我绑定了一个适配器回收适配器

  • 我在RecycleServiceAdapter中的getItemCount函数中查看数组的大小在此步骤中,新数据不会进入RecycleViewAdapter

  • MasaUrunler-Kotlin代码

    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()?.detach(masaAdisyon)?.attach(masaAdisyon)?.commit()
            }
    }
    
    var adapter : MasaAdisyonListesiAdapter? = null
    var ADISYONLISTESI = ArrayList<AdisyonListesiBilgileri>()
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
    
        var thisView = inflater.inflate(R.layout.fragment_masa_adisyon, container, false)
        var args = arguments
        var layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        thisView?.findViewById<RecyclerView>(R.id.masaAdisyonListesiRecycle)?.layoutManager = layoutManager
        adapter = MasaAdisyonListesiAdapter(ADISYONLISTESI)
        if(args?.getSerializable("ADISYONLISTESI") != null){
            ADISYONLISTESI = args?.getSerializable("ADISYONLISTESI") as ArrayList<AdisyonListesiBilgileri>
            adapter?.notifyDataSetChanged()
        }
        thisView?.findViewById<RecyclerView>(R.id.masaAdisyonListesiRecycle)?.adapter = adapter
        return thisView
    }
    inner class MasaAdisyonListesiAdapter(_ADISYONLISTESI : ArrayList<AdisyonListesiBilgileri>) : RecyclerView.Adapter<MasaAdisyonListesiAdapter.MasaAdisyonListesiViewHolder>(){
        var ADISYONLAR = _ADISYONLISTESI
        override fun getItemCount(): Int {
            Log.e("ADISYONBOYUTU",ADISYONLAR.size.toString())
            return ADISYONLAR.size
        }
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MasaAdisyonListesiViewHolder {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
        override fun onBindViewHolder(holder: MasaAdisyonListesiViewHolder, position: Int) {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
        inner class MasaAdisyonListesiViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
    
        }
    }
    
    var adisynlistesi=ArrayList()
    重写activityResult(请求代码:Int,结果代码:Int,数据:Intent?){
    super.onActivityResult(请求代码、结果代码、数据)
    if(requestCode==1){
    var gecici=AdisynListeibelgileri(
    数据?.extras!!.getDouble(“MIKTAR”),
    数据?.extras!!.getDouble(“PORSIYON”),
    数据?.extras!!.getSerializable(“URUNANABILGILERI”)作为UrunBilgileri,
    data?.extras!!.getSerializable(“SECILENOZELLIKLER”)作为ArrayList,
    data?.extras!!.getSerializable(“OZELLIKLISTESI”)作为ArrayList,
    0,
    0,
    无效的
    无效的
    无效的
    )
    ADISYONLISTESI.add(gecici)
    var bundle=bundle()
    bundle.putSerializable(“adisonlistesi”,adisonlistesi)
    var masaAdisyon=masaAdisyon()
    masaAdisyon.arguments=bundle
    var fragmentManager=getFragmentManager()
    fragmentManager?.beginTransaction()?.detach(masaAdisyon)?.attach(masaAdisyon)?.commit()
    }
    }
    
    MasaAdisyon Kotlin代码

    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()?.detach(masaAdisyon)?.attach(masaAdisyon)?.commit()
            }
    }
    
    var adapter : MasaAdisyonListesiAdapter? = null
    var ADISYONLISTESI = ArrayList<AdisyonListesiBilgileri>()
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
    
        var thisView = inflater.inflate(R.layout.fragment_masa_adisyon, container, false)
        var args = arguments
        var layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        thisView?.findViewById<RecyclerView>(R.id.masaAdisyonListesiRecycle)?.layoutManager = layoutManager
        adapter = MasaAdisyonListesiAdapter(ADISYONLISTESI)
        if(args?.getSerializable("ADISYONLISTESI") != null){
            ADISYONLISTESI = args?.getSerializable("ADISYONLISTESI") as ArrayList<AdisyonListesiBilgileri>
            adapter?.notifyDataSetChanged()
        }
        thisView?.findViewById<RecyclerView>(R.id.masaAdisyonListesiRecycle)?.adapter = adapter
        return thisView
    }
    inner class MasaAdisyonListesiAdapter(_ADISYONLISTESI : ArrayList<AdisyonListesiBilgileri>) : RecyclerView.Adapter<MasaAdisyonListesiAdapter.MasaAdisyonListesiViewHolder>(){
        var ADISYONLAR = _ADISYONLISTESI
        override fun getItemCount(): Int {
            Log.e("ADISYONBOYUTU",ADISYONLAR.size.toString())
            return ADISYONLAR.size
        }
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MasaAdisyonListesiViewHolder {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
        override fun onBindViewHolder(holder: MasaAdisyonListesiViewHolder, position: Int) {
            TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
        }
        inner class MasaAdisyonListesiViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
    
        }
    }
    
    var适配器:MasaAdisyonListesiAdapter?=无效的
    var ADISYONLISTESI=ArrayList()
    覆盖创建视图(充气机:布局充气机,容器:视图组?,
    savedInstanceState:捆绑?:查看?{
    var thisView=充气机。充气(R.layout.fragment\u masa\u adisyon,容器,false)
    var args=参数
    var layoutManager=LinearLayoutManager(上下文,LinearLayoutManager.VERTICAL,false)
    此视图?.findViewById(R.id.masaadisyonListSireCycle)?.layoutManager=layoutManager
    适配器=MasaAdisyonListesiAdapter(ADISYONLISTESI)
    if(args?.getSerializable(“adisonListesi”)!=null){
    ADISYONLISTESI=args?.getSerializable(“ADISYONLISTESI”)作为ArrayList
    适配器?.notifyDataSetChanged()
    }
    thisView?.findViewById(R.id.MasaaDisyonListSireCycle)?.adapter=适配器
    返回此视图
    }
    内部类MasaAdisyonListesiAdapter(_adisonlistesi:ArrayList):RecyclerView.Adapter(){
    var ADISYONLAR=\u ADISYONLISTESI
    重写getItemCount():Int{
    Log.e(“ADISYONBOYUTU”,adisonlar.size.toString())
    返回ADISYONLAR.size
    }
    override fun onCreateViewHolder(父级:ViewGroup,viewType:Int):MasaaDisyonListeSiveWholder{
    TODO(“未实现”)//要更改已创建函数的主体,请使用文件|设置|文件模板。
    }
    覆盖BindViewHolder(holder:MasaaDisyonListeSiveWholder,位置:Int){
    TODO(“未实现”)//要更改已创建函数的主体,请使用文件|设置|文件模板。
    }
    内部类masaaDisyonListeSiveWholder(itemView:View):RecyclerView.ViewHolder(itemView){
    }
    }
    

    **我期待你的答案。谢谢你*

    我看不到任何问题,回收服务适配器不会再次运行@timcastelijn这不是问题