Giter Site home page Giter Site logo

selectiverecycleviewinbottomsheetdialog's Introduction

SelectiveRecycleViewInBottomSheetDialog

Android native BottomsheetDialog in recycleview

Summary

This library allows you to use the BottomsheetDialog in recycleview for item/s selection.

Group-59.png

Features

  • Single option selection
  • Multiple option selection
  • Clear all selection
  • Clear current selection using close bottomsheet

Download

Step 1. Add the JitPack repository to your build file:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency:

implementation 'com.github.sagar98:SelectiveRecycleViewInBottomSheetDialog:Tag'

Use

It is recommended that you review the project to get a full understanding of library.

Step 1:- To use bottom sheet in recycleview for selection of items, you need to implement CustomBottomSheetDialogInterface and override onCustomBottomSheetSelection() method.

Example:

class MainActivity : AppCompatActivity(), CustomBottomSheetDialogInterface {

  private var sampleList: ArrayList<SelectionListObject> = ArrayList()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
     }

  override fun onCustomBottomSheetSelection(type: String) {
     when (type) {
      "Case A" -> {
           // your code here
      }
      "Case B" -> {
           // your code here
      }
   }
}

Step 2:- create arraylist which you have to provide to recycleview. This arraylist will be of type SelectionListObject() which will contain
val id: String, val value: String, var isSelected: Boolean
If you have to display preselected item/s, set isSelected- true for respective item/s.

You can simply run for loop on your actual list and create SelectionListObject with id, value of each item and then populate ArrayList<SelectionListObject>.

Step 3:- Call CustomBottomSheetDialogClass() to display bottomsheet in recycleview for items selection.

Call CustomBottomSheetDialogClass() as shown below, where you want to open bottomsheet dialog recycleview with selectable items.
Ex. On particular Button clicked action, bottomsheet dialog will open and user will select single or multiple items.

val sampleBottomSheetDialog = CustomBottomSheetDialogClass(this,
        this, "Case A", sampleList, false)
sampleBottomSheetDialog.show()
sampleBottomSheetDialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
    ViewGroup.LayoutParams.MATCH_PARENT)

Here, you need to pass five parameters to CustomBottomSheetDialogClass().
1st is ActivityContext,
2nd is extended interface listener context,
3rd is title string which will be displayed as bottomsheet title and we will use same string to differentiate between multiple BottomsheetDialog responses.
4th is actual list of items- ArrayList
5th is "isMultiSelectAllowed" boolean value.
true:- multiselection is allowed.
false:- Only single item selection is allowed.

Overrided below method from implementated interface will provide item/items selected by user. 3rd parameter in CustomBottomSheetDialogClass() is used in below overridden method to differentiate between multiple BottomsheetDialog responses.


override fun onCustomBottomSheetSelection(type: String) {
     when (type) {
      "Case A" -> {
           // your code here
      }
      "Case B" -> {
           // your code here
      }
   }

selectiverecycleviewinbottomsheetdialog's People

Contributors

akshaybjs avatar aksx73 avatar sagar98 avatar sagarmahajan19 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.