I am trying to use a spinner inside a fragment but whenever I click on it nothing happens (meaning it doesn't show me anything to select)
private fun prioritySpinner() {
//the array with all the string values
val searchPriority = resources.getStringArray(R.array.PriorityArray)
// Initializing an ArrayAdapter
val adapter = context?.let {
ArrayAdapter(
it, // Context
android.R.layout.simple_spinner_item, // Layout
searchPriority // Array
)
}
// Set the drop down view resource
adapter?.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line)
//searchPriority_ShowBugsFragment_spinner is my spinner
// Finally, data bind the spinner object with adapter
searchPriority_ShowBugsFragment_spinner?.adapter = adapter
// Set an on item selected listener for spinner object
searchPriority_ShowBugsFragment_spinner?.onItemSelectedListener = object: AdapterView.OnItemSelectedListener{
override fun onItemSelected(parent:AdapterView<*>, view: View, position: Int, id: Long){
// Display the selected item text on text view
Toast.makeText(context,"Selected "+ searchPriority[position], Toast.LENGTH_SHORT).show()
}
override fun onNothingSelected(parent: AdapterView<*>){
// Another interface callback
}
}
}
It doesn't change anything if I call the function inside the onCreateView or inside the onCreate
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
prioritySpinner()
return inflater.inflate(R.layout.fragment_show_bugs,container,false)
}
or
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
prioritySpinner()
}
Related
I am implementing a recycler view with it's items as checkbox. My data is coming from ROOM database and this recycler view is inside a dialog fragment.
Dialog Fragment :
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = ScheduleFloorDialogBinding.inflate(layoutInflater)
createProfileViewModel = CreateProfileViewModel(Application())
floorProfileDialogAdapter = FloorProfileDialogAdapter()
binding.rvFloorsForScheduling.layoutManager = LinearLayoutManager(requireActivity())
binding.rvFloorsForScheduling.adapter = floorProfileDialogAdapter
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val floorList: MutableList<String> = mutableListOf()
//Getting list of all floors
createProfileViewModel.totalFloors.observe(viewLifecycleOwner) {
Timber.d("List of floors received : $it")
val intList = it.map(String::toInt)
val maxFloorValue = intList.last()
var count = 0
try {
while (count <= maxFloorValue) {
floorList.add(count.toString())
count++
}
} catch (e: Exception) {
Timber.d("Exception: $e")
}
floorProfileDialogAdapter.getAllFloors(floorList)
Timber.d("Floor List : $floorList")
}
}
I am able to send list of data from here to my adapter.
Adapter:
class FloorProfileDialogAdapter() : RecyclerView.Adapter<FloorProfileDialogAdapter.MyViewHolder>() {
var floors = emptyList<String>()
inner class MyViewHolder(val binding: ScheduleFloorDialogItemBinding) :
RecyclerView.ViewHolder(binding.root)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = ScheduleFloorDialogItemBinding.inflate(inflater, parent, false)
return MyViewHolder(binding)
}
#SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val currentFloor = floors[position]
Timber.d("Current floor: $currentFloor")
holder.binding.floorCheckBox.text = "Floor $currentFloor"
}
override fun getItemCount(): Int {
return floors.toString().length
}
fun getAllFloors(floorsReceived: List<String>) {
Timber.d("Floors received : $floorsReceived")
this.floors = floorsReceived
}
}
Log inside the Adapter's getAllFloor method shows that list has been received:
But inside onBindViewHolder() when I use the position I get the error saying :
java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 0.
The view is already inflated when you initialized the floorProfileDialogAdapter with an empty list, it won't be changed till you use notifyDataSetChange()
it's a solution which is not recommended
or
Using ListAdapter from Androidx Recycler view Package: it has its own submit list so every time you submit a list it notifies data set change and it compares it with the previous one
Check documentation
I'm trying to populate a spinner with data using room, I'm getting no errors but my spinner isn't displaying anything. I think it might have something to do with how I'm calling initFirstUnitSpinnerData() in my onCreateView method? But I'm having no luck. I'm using kotlin.
Thanks in advance.
DAO:
#Query("SELECT firstUnit FROM conversion_table WHERE category LIKE :search")
fun getByCategory(search: String): LiveData<List<String>>
Repository:
fun getByCategory(search: String): LiveData<List<String>>{
return conversionsDAO.getByCategory(search)
}
View Model:
fun getByCategory(search: String): LiveData<List<String>> {
return repository.getByCategory(search)
}
Fragment:
class UnitsFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
private lateinit var mConversionsViewModel: ConversionsViewModel
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_units, container, false)
mConversionsViewModel = ViewModelProvider(this).get(ConversionsViewModel::class.java)
initFirstUnitSpinnerData()
return view
}
private fun initFirstUnitSpinnerData() {
val spinnerFirstUnit = view?.findViewById<Spinner>(R.id.firstUnitSpinner)
if (spinnerFirstUnit != null) {
val allConversions = context?.let {
ArrayAdapter<Any>(it, R.layout.support_simple_spinner_dropdown_item)
}
mConversionsViewModel.getByCategory("Distance")
.observe(viewLifecycleOwner, { conversions ->
conversions?.forEach {
allConversions?.add(it)
}
})
spinnerFirstUnit.adapter = allConversions
spinnerFirstUnit.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) {
Toast.makeText(requireContext(), "$allConversions", Toast.LENGTH_LONG).show()
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}
}
}
}
This is the kind of thing you should debug really - click on the left gutter for the first line of initFirstUnitSpinnerData (the val spinnerFirstUnit one), click the Debug App button up near the Run one, and it'll pause when it hits that breakpoint you added.
Then you can move through, step by step, looking at the values of stuff and checking if it looks right, and how the code executes. It's a super useful thing to learn and it'll save you a lot of headaches!
Anyway I'm guessing your problem is that you're calling initFirstUnitSpinnerData from inside onCreateView - the latter is called by the Fragment when it needs its layout view inflating, which you do and then return it to the Fragment.
So inside initFirstUnitSpinnerData, when you reference view (i.e. the Fragment's view, which it doesn't have yet, because onCreateView hasn't returned it yet) you're getting a null value. So spinnerFirstUnit ends up null, and when you null check that, it skips setting up the adapter.
Override onViewCreated (which the Fragment calls when it has its layout view) and call your function from there, it'll be able to access view then - see if that helps!
I have a fragment called MainFragment that contains a ViewPager that contains another fragment called LibraryFragment.
LibraryFragment contains a RecyclerView with a list of items that contain an ImageView. The ImageView's contents are loaded with Coil.
When an item is clicked, LibraryFragment navigates to another fragment called ArtistDetailFragment and uses the ImageView from the item.
The problem is that while the enter transition works fine, the ImageView does not return to the list item when navigating back and only fades away. Ive attached an example below:
Ive tried using postponeEnterTransition() and startPostponedEnterTransition() along with adding a SharedElementCallback but neither have worked that well. I've also ruled out Coil being the issue.
Heres LibraryFragment:
class LibraryFragment : Fragment() {
private val musicModel: MusicViewModel by activityViewModels()
private val libraryModel: LibraryViewModel by activityViewModels()
private lateinit var binding: FragmentLibraryBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentLibraryBinding.inflate(inflater)
binding.libraryRecycler.adapter = ArtistAdapter(
musicModel.artists.value!!,
BindingClickListener { artist, itemBinding ->
navToArtist(artist, itemBinding)
}
)
return binding.root
}
private fun navToArtist(artist: Artist, itemBinding: ItemArtistBinding) {
// When navigation, pass the artistImage of the item as a shared element to create
// the image popup.
findNavController().navigate(
MainFragmentDirections.actionShowArtist(artist.id),
FragmentNavigatorExtras(
itemBinding.artistImage to itemBinding.artistImage.transitionName
)
)
}
}
Heres ArtistDetailFragment:
class ArtistDetailFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = FragmentArtistDetailBinding.inflate(inflater)
sharedElementEnterTransition = TransitionInflater.from(requireContext())
.inflateTransition(android.R.transition.move)
val musicModel: MusicViewModel by activityViewModels()
val artistId = ArtistDetailFragmentArgs.fromBundle(requireArguments()).artistId
// Get the transition name used by the recyclerview ite
binding.artistImage.transitionName = artistId.toString()
binding.artist = musicModel.artists.value?.find { it.id == artistId }
return binding.root
}
}
And heres the RecyclerView Adapter/ViewHolder:
class ArtistAdapter(
private val data: List<Artist>,
private val listener: BindingClickListener<Artist, ItemArtistBinding>
) : RecyclerView.Adapter<ArtistAdapter.ViewHolder>() {
override fun getItemCount(): Int = data.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemArtistBinding.inflate(LayoutInflater.from(parent.context))
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(data[position])
}
// Generic ViewHolder for an artist
inner class ViewHolder(
private val binding: ItemArtistBinding
) : RecyclerView.ViewHolder(binding.root) {
// Bind the view w/new data
fun bind(artist: Artist) {
binding.artist = artist
binding.root.setOnClickListener { listener.onClick(artist, binding) }
// Update the transition name with the new artist's ID.
binding.artistImage.transitionName = artist.id.toString()
binding.executePendingBindings()
}
}
}
EDIT: I used postponeEnterTransition and startPostponedEnterTransition like this:
// LibraryFragment
override fun onResume() {
super.onResume()
postponeEnterTransition()
// Refresh the parent adapter to make the image reappear
binding.libraryRecycler.adapter = artistAdapter
// Do the Pre-Draw listener
binding.libraryRecycler.viewTreeObserver.addOnPreDrawListener {
startPostponedEnterTransition()
true
}
}
This only makes the RecyclerView itself refresh however, the shared element still fades away instead of returning to the RecyclerView item.
Chris Banes says;
You may wonder why we set the OnPreDrawListener on the parent rather than the view itself. Well that is because your view may not actually be drawn, therefore the listener would never fire and the transaction would sit there postponed forever. To work around that we set the listener on the parent instead, which will (probably) be drawn.
https://chris.banes.dev/fragmented-transitions/
try this;
change
// LibraryFragment
override fun onResume() {
super.onResume()
postponeEnterTransition()
// Refresh the parent adapter to make the image reappear
binding.libraryRecycler.adapter = artistAdapter
// Do the Pre-Draw listener
binding.libraryRecycler.viewTreeObserver.addOnPreDrawListener {
startPostponedEnterTransition()
true
}
}
enter code here
to
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
postponeEnterTransition()
binding = FragmentLibraryBinding.inflate(inflater)
binding.libraryRecycler.adapter = ArtistAdapter(
musicModel.artists.value!!,
BindingClickListener { artist, itemBinding ->
navToArtist(artist, itemBinding)
}
)
(view?.parent as? ViewGroup)?.doOnPreDraw {
// Parent has been drawn. Start transitioning!
startPostponedEnterTransition()
}
return binding.root
}
i have a fragment with a BottomNavigationView, a Spinner and a FrameLayout, in the FrameLayout appears a a new fragment with the BottomNavigationView.setOnNavigationItemSelectedListener, this is my code:
Fragment ValcuotaEvolFragment
class ValcuotaEvolFragment: Fragment() {
lateinit var fragment : Fragment
override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?, savedInstanceState: Bundle?): View? {
val root = inflater.inflate(R.layout.fragment_valcuota_evol, container, false)
val menuBottom: BottomNavigationView = root.findViewById(R.id.nav_view_valcuota_evol)
val spn : Spinner = root.findViewById(R.id.spnAFP)
val db = DataBaseHandler(activity!!.applicationContext)
val afpListName : ArrayList<String> = db.getAFPNames()
fragment= ValcuotaChartFragment()
val bundle = Bundle()
spn.adapter= ArrayAdapter<String>(activity!!.applicationContext,android.R.layout.simple_spinner_dropdown_item,afpListName)
spn.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
bundle.putString("afp",spn.selectedItem.toString())
}
override fun onNothingSelected(parent: AdapterView<*>) { }
}
menuBottom.setOnNavigationItemSelectedListener {
menuItem ->
when(menuItem.itemId){
R.id.nav_evolcuota_chart -> {
fragment = ValcuotaChartFragment()
}
R.id.nav_evolcuota_data -> {
fragment = ValcuotaDataFragment()
}
}
fragment.setArguments(bundle);
val transaction = childFragmentManager.beginTransaction()
transaction.replace(R.id.frame_valcuota_evol, fragment)
transaction.addToBackStack(null)
transaction.commit()
true
}
fragment.setArguments(bundle);
val transaction = childFragmentManager.beginTransaction()
transaction.replace(R.id.frame_valcuota_evol, fragment)
transaction.addToBackStack(null)
transaction.commit()
return root
}
}
I pass to the new fragment the value "afp" through a Bundle, now i need the new fragment to do something different depending on what I select in the spinner of ValcuotaEvolFragment
this is what i need:
class ValcuotaDataFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val root = inflater.inflate(R.layout.fragment_valcuota_data, container, false)
val afp = arguments!!.getString("afp")
if(afp == "something"){
doSomething()
else {
doSomethingElse
}
return root
}
}
this actually works, but only when i change the item in the BottomNavigationView i need this works when change the item in the Spinner, thx
EDIT
The EventBus solution works fine , but now i have a new problem in ValcuotaDataFragment i have a RecyclerView, so now i need fill the RecyclerView after change the item in the Spinner, this is how i do it now:
val rcViewValcuota = root. findViewById(R.id.rc_valcuota_data) as RecyclerView
var valcuota : MutableList<ValcuotaModel>
val db = DataBaseHandler(activity!!.applicationContext)
valcuota = db.getCompleteValCuota(spinnerData.selectedItem,"desc")
rcViewValcuota.adapter= ContentValcuotaMonthlyAdapter(valcuota)
i can't access the "root" from the function listenItemChange
Okay, so when you're selecting a different item from the spinner, your fragment is not aware of it unless you pass data to fragment. So for informing the fragment, you can implement the interface if you'd like. Or my favorite you can use EventBus library to pass the data.
I'll show you how you can implement EventBus.
First, add EventBus Dependency is the Gradle file:
implementation 'org.greenrobot:eventbus:3.1.1'
Okay now create a data class for passing data say SpinnerData:
data class SpinnerData(val selectedItem:String)
Then inside your itemSelected listener, pass the data using EventBus:
spn.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
// bundle.putString("afp",spn.selectedItem.toString())
//insted add following line
EventBus.getDefault().post(SpinnerData(spn.selectedItem.toString()))
}
override fun onNothingSelected(parent: AdapterView<*>) { }
}
Then inside your ValcuotaDataFragment add the following:
#Subscribe
fun listenItemChange(spinnerData: SpinnerData){
if (spinnerData.selectedItem == "something") {
doSomething()
} else {
doSomethingElse()
}
}
override fun onStart() {
super.onStart()
EventBus.getDefault().register(this)
}
override fun onStop() {
EventBus.getDefault().unregister(this)
super.onStop()
}
Now, whenever you change the spinner item Evenbus will be triggered and pass the data to the Subscribed method inside your fragment.
Hope this helps, let me know if you get stuck somewhere.
Edit:
This won't work if your fragment isn't initialized already.
SO keep your line inside your itemSelected listener for first time use:
bundle.putString("afp",spn.selectedItem.toString())
I have a small app. 1 Activity (MainActivity.kt) and two Fragments (MainFragment & CreateNewJobFragment).
Mainfragment has a Recyclerview. CreateNewJobFragment contains a 6 spinners and an edittext. I'm attempting to have the selections from the spinners and edittext to populate the RecyclerView when the user makes their choices and clicks a "create job" button.
The issue is, when this button is clicked, the app will go back up the backstack to the MainFragment, but instead of populating the recyclerview with a new item, it runs through onCreate again and nothing happens.
MainFragment.kt
class MainFragment : Fragment() ,ItemClickedCustomListener{
override fun onCustomSpinnerItemSelected(selectedItems: JobData) {
Log.v("MainFragment","onCustomSpinnerItemSelected")
Log.v("MainFragment","selectedItems --> "
+ selectedItems.companyName + " "
+ selectedItems.location + " "
+ selectedItems.pumpTruck + " "
+ selectedItems.smartPiggers)
jobs.add(selectedItems)
adapter = recyclerView.adapter as JobAdapter
adapter.data(jobs)
}
var jobs = ArrayList<JobData>()
lateinit var adapter : JobAdapter
private lateinit var binding: FragmentMainBinding
lateinit var recyclerView : RecyclerView
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (savedInstanceState == null) {
binding = FragmentMainBinding.inflate(inflater)
//getting recyclerview from xml and binding it
recyclerView = binding.jobRecyclerView
//adding a layoutmanager
recyclerView.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
//Arraylist to store jobs using the data class JobData.
// TODO: Change this to a user created list from CreateNewJobFragment.kt
jobs = ArrayList()
Log.v("MainFragment", "onCreateView --> ")
//creating adapter
adapter = JobAdapter(jobs)
//add adapter to recyclerView
recyclerView.adapter = adapter
//Setting onClickListener for FAB(floating action button) using Navigation
binding.createNewJobFAB.setOnClickListener { v: View ->
v.findNavController().navigate(R.id.action_mainFragment_to_createNewJobFragment)
}
}
return binding.root
}
}
CreateNewJobFragment.kt
class CreateNewJobFragment : Fragment() {
private lateinit var binding: FragmentCreateNewJobBinding
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = FragmentCreateNewJobBinding.inflate(inflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
var addJobToRecyclerview = JobData("","","","")
//String array.
//TODO: Move this to res/strings
val companyNames = arrayOf("Company A", "Company B", "Company C", "Company D", "Company E")
var nameSpinner = binding.spinnerCustomerName
//Adapter for spinner
nameSpinner.adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_dropdown_item, companyNames)
//item selected listener for spinner
nameSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(p0: AdapterView<*>?) {
TODO("not implemented yet")
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
//user selected spinner choice added
addJobToRecyclerview.companyName = companyNames[p2]
}
}
//String array.
//TODO: Move this to res/strings
val refineryTown = arrayOf("Long Beach", "Houston", "Cherry Point", "Wood River", "Bismark")
var townSpinner = binding.spinnerLocation
//Adapter for spinner
townSpinner.adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_dropdown_item, refineryTown)
//item selected listener for spinner
townSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(p0: AdapterView<*>?) {
TODO("not implemented yet")
}
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
addJobToRecyclerview.location = refineryTown[p2]
}
}
<SNIP>Cutting out 5 repeated spinners and editText to save some space</SNIP>
//Setting onClickListener for 'Create Job' button using Navigation
binding.buttonCreateJob.setOnClickListener { v: View ->
(activity as MainActivity).itemClickedCustomListener.onCustomSpinnerItemSelected(addJobToRecyclerview)
Log.v("CreateNewJobFragment", "Job data added -->$addJobToRecyclerview")
Log.v("CreateNewJobFragment", "Create job button --> clicked")
v.findNavController().navigate(R.id.action_createNewJobFragment_to_mainFragment)
}
}
}
I'm using the following Android documentation as a guide: Implementing Navigation
And this part in particular for the navigation back to MainFragment: Tie destinations to UI widgets
After clicking the "Create Job" button. App does go back to MainFragment. But as mentioned, nothing shows in Recyclerview.
I've some some logging in place. This is from the logs:
Log sample
2018-12-07 22:03:17.959 5806-5806/com.palarran.pigtimer V/MainActivity: onCustomSpinnerItemSelected
2018-12-07 22:03:17.959 5806-5806/com.palarran.pigtimer V/MainActivity: selectedItems --> Company A Long Beach Company 1 Company 4
2018-12-07 22:03:17.960 5806-5806/com.palarran.pigtimer V/CreateNewJobFragment: Job data added -->JobData(companyName=Company A, location=Long Beach, pumpTruck=Company 1, smartPiggers=Company 4)
2018-12-07 22:03:17.960 5806-5806/com.palarran.pigtimer V/CreateNewJobFragment: Create job button --> clicked
2018-12-07 22:03:18.026 5806-5806/com.palarran.pigtimer V/MainFragment: onCreateView -->
2018-12-07 22:03:18.146 5806-5806/com.palarran.pigtimer V/JobAdapter: getItemCount 0
2018-12-07 22:03:18.146 5806-5806/com.palarran.pigtimer V/JobAdapter: getItemCount 0
As you can see, after the log entry for "Create job button --> clicked", it jumps to "onCreateView" in the MainFragment and the item count in my custom adapter(JobAdapter.kt) does not increase.
JobAdapter.kt
class JobAdapter(private var jobList: ArrayList<JobData>) : RecyclerView.Adapter<JobAdapter.ViewHolder>() {
//Returning view for each item in the list
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JobAdapter.ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.job_list_item, parent, false)
Log.v("JobAdapter","onCreateViewHolder")
return ViewHolder(v)
}
//Binding the data on the list
override fun onBindViewHolder(holder: JobAdapter.ViewHolder, position: Int) {
Log.v("JobAdapter","onBindViewHolder")
holder.bindItems(jobList[position])
}
override fun getItemCount(): Int {
Log.v("JobAdapter","getItemCount " + jobList.size)
return jobList.size
}
fun data(jobs: ArrayList<JobData>) {
Log.v("JobAdapter","DataSetChanged")
jobList = jobs
notifyDataSetChanged()
}
//Class holds the job list view
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindItems(job: JobData) {
val textViewCompanyName = itemView.findViewById(R.id.tv_companyName) as TextView
val textViewLocation = itemView.findViewById(R.id.tv_job_location) as TextView
textViewCompanyName.text = job.companyName
Log.v("JobAdapter", "bindItems" + textViewCompanyName.text)
textViewLocation.text = job.location
Log.v("JobAdapter", "bindItems" + textViewLocation.text)
}
}
}
Am I missing something in the documents or reading them incorrectly? I'm definitely misunderstanding something.
Late responding to this.
I was able to get this figured out. By using Sugar ORM database. Calling it in onResume() in my MainFragment.
It was a dumb question that I should have researched more before posting.