Skip to content

Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

Notifications You must be signed in to change notification settings

ICADB/SpinnerDialog

 
 

Repository files navigation

SpinnerDialog

Android Spinner Dialog Library, Use for single or multi selection of choice

Download

Android UI

Download

To include SpinnerDialog in your project, add the following to your dependencies:

app/build.gradle

dependencies {
        implementation 'com.github.hamzaahmedkhan:SpinnerDialog:v1.1.0'
}

Usage

The following snippet shows how you can use Spinner Dialog in your project.

In Java

public class MainActivity extends Activity {
    
    
    //... other variables
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
            // Set Data
            
           ArrayList<SpinnerModel> arrSpinners = new ArrayList<>();
        
           for (int i = 0; i < 5; i++) {
               arrSpinners.add(new SpinnerModel("Number " + i));
           }
        
           // Init Fragment
           SpinnerDialogFragment spinnerDialogFragment = SpinnerDialogFragment.Companion.newInstance("Demo", arrSpinners, (data, selectedPosition) -> UIHelper.showToast(getContext(), data.getText()), 0);
           
           // Show Fragment
           spinnerDialogFragment.show(getActivity().getSupportFragmentManager(), "spinnerDialog");

    }
}

In Kotlin

class MainActivity : AppCompatActivity() {


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


        val arraySpinnerModel: ArrayList<SpinnerModel> = ArrayList()

        for (i in 1..9) {
            arraySpinnerModel.add(SpinnerModel("Number $i"))
        }


        // Init Fragment
        val spinnerDialogFragment =
            SpinnerDialogFragment.newInstance(
                "Spinner Dialog", arraySpinnerModel,
                object : OnSpinnerOKPressedListener {
                    override fun onItemSelect(data: SpinnerModel, selectedPosition: Int) {
                        Toast.makeText(applicationContext, data.text, Toast.LENGTH_LONG).show()
                    }

                }, 0
            )


        txtShowSingleChoiceSpinner.setOnClickListener { spinnerDialogFragment.show(supportFragmentManager, "SpinnerDialogFragment") }
        txtShowMultiChoiceSpinner.setOnClickListener { Toast.makeText(applicationContext, "In Progress", Toast.LENGTH_LONG).show() }
    }
}

EXTRA ATTRIBUTES

        // Using optional features
        spinnerDialogFragment.buttonText = "SAVE"
        spinnerDialogFragment.themeColorResId = resources.getColor(R.color.material_pink500)
        spinnerDialogFragment.showSearchBar = true
        spinnerDialogFragment.searchbarHint = "type here to search.."

FUTURE PLANS

-> Multi check options -> Description option

About

Android Spinner Dialog Library supported on both Java and Kotlin, Use for single or multi selection of choice

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 60.8%
  • Java 39.2%