如何将 textView 和 imageView(从字符串和可绘制对象)加载到导航到的片段中,从 recyclerView

发布于 2025-01-12 01:30:04 字数 1756 浏览 0 评论 0原文

我在这里问了一个类似的问题这里。但我觉得我没有表达得淋漓尽致。所以我正在详细说明。

我想从 recyclerView 导航到的片段上加载 textView 和 imageView (来自字符串和可绘制对象)。

请注意我正在使用导航组件。

我对此有点陌生,但我已经做了一些工作并发现我可以使用 intent,然后导航到Activity 并使用 Intent putExtra 加载我想要加载的任何内容,但是我使用的是单个 Activity 和多个片段模型。所以我不能这样做。

我已经这样做了一个多星期了,所以我非常感谢任何帮助。即使这只是我需要使用的工具的名称..但我不介意一些代码,非常感谢您的帮助,提前。

我不知道您需要什么信息,所以我只添加我认为重要的信息。如果需要,我会提供任何信息,谢谢。

这是导航到片段的 recyclerView 适配器:

class StoriesRecyclerAdapter(private val storiesList: ArrayList<StoriesDataClass>) : RecyclerView.Adapter<StoriesRecyclerAdapter.ViewHolder>() {

    // create new views
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        ...

        return ViewHolder(view)
    }

    // binds the list items to a view
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        ...

        // navigates to stories content destination
        holder.storiesCardView.setOnClickListener {
            val action = StoriesFragmentDirections.actionNavigationStoriesToStoriesContentFragment()
            holder.itemView.findNavController().navigate(action)
        }
    }

    // return the number of the items in the list
    override fun getItemCount(): Int {
        ...
    }

    // Holds the views for adding it to image and text
    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val storiesCardView : CardView = itemView.findViewById(R.id.stories_cardView)
        ...
    }
}

如果您需要更多信息,请通知我,我真诚地感谢您的时间和反馈。

I asked a similar question here. But I feel I didn't express myself vividly. So I'm elaborating.

I want to load textView and imageView (from strings & drawables) on the fragment that is navigated to, from recyclerView.

Please note I am using navigation component.

I am kinda new to this, but I'm done some reach and find out that I could used intent, and just navigate to an activity and use intent putExtra to load whatever I want to load, but I am using single activity and mutiple fragment model. So I can't do this.

I have been at this for over a week, so I'd really appreciate any help. Even if it's just the name of the tool I need to use.. But I wouldn't mind some code, thanks a lot for your help, in advance.

I don't know what info you will need, so I'll just add what I feel is important. I will provide any info if requested thanks.

Here's the recyclerView Adapter, that navigate into the fragment:

class StoriesRecyclerAdapter(private val storiesList: ArrayList<StoriesDataClass>) : RecyclerView.Adapter<StoriesRecyclerAdapter.ViewHolder>() {

    // create new views
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        ...

        return ViewHolder(view)
    }

    // binds the list items to a view
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        ...

        // navigates to stories content destination
        holder.storiesCardView.setOnClickListener {
            val action = StoriesFragmentDirections.actionNavigationStoriesToStoriesContentFragment()
            holder.itemView.findNavController().navigate(action)
        }
    }

    // return the number of the items in the list
    override fun getItemCount(): Int {
        ...
    }

    // Holds the views for adding it to image and text
    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val storiesCardView : CardView = itemView.findViewById(R.id.stories_cardView)
        ...
    }
}

Please inform me if you need any more info, I sinerely thank you for your time and feedback.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉溺在你眼里的海 2025-01-19 01:30:04
禾厶谷欠 2025-01-19 01:30:04

您可以使用intent.extra传递数据

findNavController(R.id.main_content).setGraph(R.navigation.<you_nav_graph_xml>, intent.extras)

或使用bundle传递数据

val bundle = Bundle()
bundle.putString("some_argument", "some_value")
navController.setGraph(R.navigation.<you_nav_graph_xml>, bundle)

you can use intent.extra to pass data

findNavController(R.id.main_content).setGraph(R.navigation.<you_nav_graph_xml>, intent.extras)

or bundle to pass data

val bundle = Bundle()
bundle.putString("some_argument", "some_value")
navController.setGraph(R.navigation.<you_nav_graph_xml>, bundle)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文