android-fragments 当我单击回收站查看器中的项目时,我试图打开另一个对话框片段

kxxlusnw  于 2022-11-13  发布在  Android
关注(0)|答案(1)|浏览(150)

我尝试打开另一个对话框片段,代码如下:

private  fun showList() {

    val job = Job()
    val scopeMainThread = CoroutineScope(job + Dispatchers.Main)
    val scopeIO = CoroutineScope(job + Dispatchers.IO)

    val adapter = ServerListAdapter()
    val recyclerView = binding.rvConnList

    binding.rvConnList.addItemDecoration(
        DividerItemDecoration(
            activity,
            DividerItemDecoration.VERTICAL
        )
    )

    recyclerView.adapter = adapter
    recyclerView.layoutManager = GridLayoutManager(activity, 1)

    val serverViewModel= ViewModelProvider(this)[ServerViewModel::class.java]
    scopeIO.launch {
        val x = serverViewModel.getAll()
        scopeMainThread.launch {
            activity?.let {
                x.observe(it) { s ->
                    s?.let { it ->
                        adapter.setData(it)
                        adapter.onItemClick = {

                            SyncSovEntryFragment(Date(), it).apply {
                                setListener { _, year, month, dayOfMonth ->
                                    Toast.makeText(requireContext(), "Set date: $year/$month/$dayOfMonth", Toast.LENGTH_LONG).show()
                                }
                                activity?.let { it1 -> show(it1.supportFragmentManager, "MonthYearPickerDialog") }
                            }

                            Toast.makeText(activity, it.database, Toast.LENGTH_LONG).show()
                            dismiss()
                        }
                    }
                }
            }

        }
    }
}

我正在尝试打开另一个对话框片段,是否有其他方法可以在对话框片段中调用supportFragmentManager?因为以下代码不起作用:
活动?.let {it 1-〉show(it1.supportFragmentManager,“月/年选取器对话框”)}
谢谢你,谢谢。

72qzrwbm

72qzrwbm1#

打开适配器中Activity或片段,如下所示

holder.itemlayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Intent intent;
            intent =  new Intent(context, yourfragment.class);
          
            context.startActivity(intent);
        }



    });

itemlayout是您的recycler的主布局查看要单击的项目

相关问题