Reputation: 355
data class OptionState(
val option : Options = Options.OPTION1) {
enum class Options(
val optionSelected : Boolean = false) {
OPTION1(false),
OPTION2(false),
OPTION3(false),
OPTION4(false)
}
}
@Composable
fun AvailOptions(
optionState: OptionState ,
onSelect : (OptionState.Options) -> Unit
) {
val (optionButton , setOptionButton) = remember {
mutableStateOf(
OptionState.Options.values().indexOf(optionState.option)
)
}
Column(
modifier = Modifier,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
PossibleAnswer(optionText = "option 1" )
PossibleAnswer(optionText = "option 2" )
PossibleAnswer(optionText = "option 3" )
PossibleAnswer(optionText = "option 4" )
}
}
Upvotes: 2
Views: 488
Reputation: 348
I suggest you make it flexible.
To display answer options, use the RecyclerView list, for example, so you will not be tied to the number of answer options and their type, especially since you can use not just a String or Enum, but an object of a certain model, which may be different (text question, video question, etc. other, you can also put a property in the model that means the parity of this answer, there can be several correct options, etc.) This will allow you to download answer options from any repository (local or remote using a full backend or Firebase).
In order to process the press, send an onClickListener to the adapter, so you will find out which option was selected and process this press in the ViewModel or Presenter without overload the adapter.
If you have multiple answers, you can use SelectionTracker to track the selected items.
Upvotes: 3
Reputation: 335
Try to use RadioGroup
, that will managed by Android
itself. Not needed to create to much logic.
Upvotes: 0