Closed Pirokar closed 6 years ago
Hi @Pirokar,
Could you provide a bit more context, please? How would you like for this to work exactly?
If you have an array of items you would like to iterate over, you can add an item for each of them dynamically I guess. This should be similar to one of the samples in the sample app: see onConditionalItemsClicked
in DarkActivity
or LightActivity
. There's an if
statement there but this could easily be e.g. a for-each loop.
@zawadz88 this allows you to check that "if we have "A" item in array, than add "A". I want to write:
val section = MaterialPopupMenuBuilder.SectionHolder()
for(menuListItem in listToImplement) {
section.customItem {
layoutResId = R.layout.item_filters_menu
viewBoundCallback = { view ->
val imageView = view.findViewById<ImageView>(R.id.filterImageFilters)
val textView = view.findViewById<TextView>(R.id.itemTextFilters)
val countView = view.findViewById<TextView>(R.id.communityCountTextFilters)
imageView.setImageResource(menuListItem.imageResourceId)
countView.text = menuListItem.ticketsCount.toString()
menuListItem.type.getTextForEnum()
}
callback = {
toast("Clicked!")
}
}
}
val builder = MaterialPopupMenuBuilder()
builder.addSection(section)
openPopupMenu = builder.build()
But this is impossible with current tools. I'm already connect your library as a module from your sourceCode and all that I need to make it work it's add this method:
fun addSection(sectionHolder: SectionHolder) {
sectionHolderList.add(sectionHolder)
}
You can do following e.g.:
section {
if (true) {
item {
label = "Dynamic item based on bool"
}
}
for (i in 0..10) {
item {
label = "Dynamic item $i"
}
}
item {
label = "Static item"
}
}
And similar. Was looking for the same like you and came to this solution...
Thanks @MFlisar!
Looks like you allows only static way to create views.