https://github.com/iamriajul/onlinespinner
OnlineSpinnerView Android library to help you with Loading data into Spinner from server/online, with Support of Search, Default Value Selection, Loading callback.
https://github.com/iamriajul/onlinespinner
android-library android-view online-spinner select2 select2-android spinner
Last synced: about 1 month ago
JSON representation
OnlineSpinnerView Android library to help you with Loading data into Spinner from server/online, with Support of Search, Default Value Selection, Loading callback.
- Host: GitHub
- URL: https://github.com/iamriajul/onlinespinner
- Owner: iamriajul
- License: apache-2.0
- Created: 2018-08-12T06:00:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-06T03:46:15.000Z (over 6 years ago)
- Last Synced: 2025-01-24T05:11:25.218Z (3 months ago)
- Topics: android-library, android-view, online-spinner, select2, select2-android, spinner
- Language: Java
- Homepage:
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://jitpack.io/#iamriajul/OnlineSpinner)
# OnlineSpinnerView
help you to implement Spinner view with Online Data support + Searchable + callback and more.
This Library was Inspired by the [Select2](https://select2.org) web library.
Usage:
---layout:
Searchable
---
```xml```
Not Searchable
---
```xml```
code:Your api url must return json, with id, second_column (second_column can be custom specified when using load method or you can leave null to detect automatically) field like this
```json
[
{"id":"0", "second_column":"Item 1"},
{"id":"1", "second_column":"Item 2"},
{"id":"2", "second_column":"Item 3"}
]
```
####**If you have have multiple column in a row like this**
```json
[
{"id":"0", "timestamp":"1534216256", "lang": "Arabic"},
{"id":"1", "timestamp":"1534216256", "lang": "English"},
{"id":"2", "timestamp":"1534216256", "lang": "Bengali"}
]
```
#####**Then you can specify which column to use in user interface, like this: **
```kotlin
example2.load(this, "http://example.com/language/all", 0, "lang") // custom specified column name and selected is Arabic
```Your Activity or Fragment must `ActivityWithOnlineSpinner` interface.
Kotlin
======
Loading Data
---
```kotlin
showLoader()
// Change dataUrl with your real data url
example.load(this, "http://example.com/country/all", 5)
example2.load(this, "http://example.com/language/all", 0, "lang") // custom specified column name
// It will call hideLoader when all spinner successfully loaded with data.
```Getting Selected Item Id (Example On Submit Handle)
---
```kotlin
submitBtn.setOnClickListener{
val exampleId: Int = example.getSelectedItemId()
val example2Id: Int = example2.getSelectedItemId("lang")
// Here is your data, You can process this data as you want.
}
```Selection Change Listener with Lambda
---
```kotlin
example.setOnItemSelectedListener { id, item ->
}
```Selection Change Listener without Lambda
---
```kotlin
example.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
```Implementing Callback
---
```kotlin
override var totalFieldsCount: Int = 2 // Total OnlineSpinner fields in this activity is using
override var fieldsLoaded: Int = 0 // it should be 0override fun hideLoader() {
// Hide loading animation, or anything you want.
}override fun showLoader() {
// Show loading animation, or anything you want.
}// Optional Callback // this is same as hideLoader()
override fun onOnlineSpinnerCompleted() {
// Loading other text fields
}```
Java
======
```java
showLoader()
OnlineSpinner example = (OnlineSpinner) findViewById(R.id.example);
OnlineSpinner example2 = (OnlineSpinner) findViewById(R.id.example2);
// Change dataUrl with your real data url
example.load(this, "http://example.com/country/all", 5)
example2.load(this, "http://example.com/language/all", 3, "lang") // custom specified column name
// It will call hideLoader when all spinner successfully loaded with data.
```Fields
======================
Name | Type | Description
--- | --- | ---
`totalFieldsCount` | Integer | Count of OnlineSpinner in your current Activity, this field is to help the library to detect if all Spinner loaded or not to trigger `hideLoader()`
`fieldsLoaded` | Integer | This field should be init with 0, It will be incremented by the Library with each OnlineSpinner loaded.Methods
======================
Name | Description
--- | ---
`showLoader()` | Call this method once before start calling `OnlineSpinner.load()`
`hideLoader()` | This method will be called by the Library when all the Spinner loading will complete successfully.
`onOnlineSpinnerCompleted()` | (Optional Override) This method will be called by the Library when all the Spinner loading will complete successfully.dependency
---
Add it in your root build.gradle at the end of repositories:```groovy
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
```
add dependency:```groovy
dependencies {
implementation 'com.github.iamriajul:OnlineSpinner:2.0'
}
```Thanks...