• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Giving Context to Fragment

Resolved: Giving Context to Fragment

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I’m trying to give context using “this” to a adapter
Code is:
Data Class:
Adapter Code:
}
Type mismatch. Required: Activity

Answer:

Change
class ShoeAdapter(private val context: Activity,...
to
class ShoeAdapter(private val context: Context,...
and
binding.listviewProfile.adapter = ShoeAdapter(this,shoeArrayList)
to
context?.run { binding.listviewProfile.adapter = ShoeAdapter(this,shoeArrayList) }
You could also keep the Activity but the adapter doesn’t need an Activity so it’s best to go with the more abstract Context.

If you have better answer, please add a comment about this, thank you!

android android-studio kotlin
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: EntityFramework creates/runs migrations using parameterless DataContext instance

24/03/2023

Resolved: Visual Studio 2022 crashes when using breakpoints

24/03/2023

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.