Home > Back-end >  I am building a News Application in Android. I have to create a filter for category. I want to creat
I am building a News Application in Android. I have to create a filter for category. I want to creat

Time:09-24

enter image description here

I don't know what i am supposed to use to build a filter like this.

CodePudding user response:

Since your question is tagged with Material Design, i guess you're looking for the appropriate ui-element:

It's called Chip, see https://material.io/components/chips

Please note it's looking different depending on Material Design version.

CodePudding user response:

Try this, You can adapt with your own logic

MainActivity.kt

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        setupCategories()
}

fun setupCategories() {
    val layoutInflater = LayoutInflater.from(this)
    val chipGroup = findViewById<ChipGroup>(R.id.chip_group)
    chipGroup.removeAllViews()

    val categories = listOf("All", "           
  • Related