Oziomajnr / WheelSelector

An android view for selecting items by spinning a wheel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Set up items with For Loop with steps

apjoex opened this issue · comments

This could save a lot of lines while setting up the items.

Thanks, can you provide a code sample so I can get a better context.

Hi, so after a quick research I realised that since we are working with Floats, what Kotlin provides is ClosedFloatingPointRange which isn't completely suitable for my suggestion.

However, I have gone ahead added a code snippet with tweaks for converting Ints to Floats for your consideration.

val items = (5..20).map { WheelSelectorItem(value = it.toFloat()/10, highlight = listOf(5,10,15,20).contains(it)) }

👆🏽 gives the same output as 👇🏽 in your README but saves a ton of lines.

private val items: List<WheelSelectorItem> = listOf(  
WheelSelectorItem(0.5f, true),  
  WheelSelectorItem(0.6f),  
  WheelSelectorItem(0.7f),  
  WheelSelectorItem(0.8f),  
  WheelSelectorItem(0.9f),  
  WheelSelectorItem(1.0f, true),  
  WheelSelectorItem(1.1f),  
  WheelSelectorItem(1.2f),  
  WheelSelectorItem(1.3f),  
  WheelSelectorItem(1.4f),  
  WheelSelectorItem(1.5f, true),  
  WheelSelectorItem(1.6f),  
  WheelSelectorItem(1.7f),  
  WheelSelectorItem(1.8f),  
  WheelSelectorItem(1.9f),  
  WheelSelectorItem(2.0f, true)  
) 

Thanks, that is just a sample to indicate how clients can initialize the items... you can initialize it however you want... e.g fetch from the server or local storage or with loops...

I would also add your method of initialization to the README thanks.