如何将 textView 和 imageView(从字符串和可绘制对象)加载到导航到的片段中,从 recyclerView
我在这里问了一个类似的问题这里。但我觉得我没有表达得淋漓尽致。所以我正在详细说明。
我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查这个链接它很容易工作
https://developer.android.com/guide/navigation/navigation-pass-数据
check this link out its pretty easy to work
https://developer.android.com/guide/navigation/navigation-pass-data
您可以使用intent.extra传递数据
或使用bundle传递数据
you can use intent.extra to pass data
or bundle to pass data