Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKhurram Shahzad
3,695 PointsSwitch states are not showing up in checked form
I have followed your videos but I am not able to see the switch in checked states. can you please have a look, what's wrong in it ?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_creator)
pizzaId = intent.getIntExtra(PIZZA_ID, -1)
viewModel= ViewModelProviders.of(this).get(CreaterViewModel::class.java)
thread {
if (pizzaId != -1) {
viewModel.pizzaName=db.pizzaDao().getPizzaById(pizzaId).name
val toppingIds=db.pizzaToppingDao().getToppingIdForPizzaId(pizzaId)
toppingIds.forEach{
val topping= db.ToppingDao().getToppingById(it)
viewModel.switchStates[topping]=true
}
runOnUiThread {
title=viewModel.pizzaName
}
}
}
pizzaView = PizzaView(this,viewModel.switchStates)
val frameLayout = findViewById<FrameLayout>(R.id.frameLayout)
frameLayout.addView(pizzaView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
val adapter = CreatorAdapter(pizzaView,viewModel)
val recyclerView = findViewById<RecyclerView>(R.id.toppingsRecyclerView)
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recyclerView.adapter = adapter
adapter.list.addAll(toppings)
}
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherHey Khurram! Nothing's jumping out at me as incorrect. Do you have the project on GitHub? I can run it and see if I can find the problem that way.