Skip to content

Commit

Permalink
Attempt at fix for changing spinner items
Browse files Browse the repository at this point in the history
  • Loading branch information
MattJAshworth committed Jan 20, 2025
1 parent 14e817e commit 68ad6b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SpinnerTools/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ android {
from(components["release"])
groupId = "xyz.mattjashworth.spinnertools"
artifactId = "SpinnerTools"
version = "1.4"
version = "1.4.5"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Spinner<T>(context: Context, attributeSet: AttributeSet) : LinearLayout(co
selectedItem.setTextColor(textColor ?: context.getColor(android.R.color.black))

setChildListener(rootView, OnClickListener {
val s = SpinnerSheet<T>(context, items, title, displayMember, searchable)
val s = SpinnerSheet<T>(context, this.items, title, displayMember, searchable)
if (selectedObject != null)
s.setSelectedObject(selectedObject!!)
s.setOnItemClickListener(object : SpinnerSheet.OnSearchSpinnerClickListener<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal class SpinnerSheet<T>(context: Context, items: ArrayList<T>, title: Str

init {

filteredItems = ArrayList(items.toList())

diag = BottomSheetDialog(context)
val layoutInflater = LayoutInflater.from(context)
Expand Down
21 changes: 16 additions & 5 deletions sample/src/main/java/xyz/mattjashworth/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import xyz.mattjashworth.spinnertools.sheet.Spinner

class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -60,15 +64,22 @@ class MainActivity : AppCompatActivity() {
)


val searchSpinner = findViewById<Spinner<ExampleObject>>(R.id.app_spinner)
searchSpinner.setItems(data)
searchSpinner.setOnItemSelectedListener(object : Spinner.OnItemSelectedListener<ExampleObject> {
override fun onItemSelected(model: ExampleObject) {
Snackbar.make(rootView, model.name, Snackbar.LENGTH_LONG).show()
val searchSpinner = findViewById<Spinner<String>>(R.id.app_spinner)
searchSpinner.setItems(arrayListOf("One", "Two", "Three", "Four", "Five", "Six"))
searchSpinner.setOnItemSelectedListener(object : Spinner.OnItemSelectedListener<String> {
override fun onItemSelected(model: String) {
Snackbar.make(rootView, model, Snackbar.LENGTH_LONG).show()
}

})

CoroutineScope(Dispatchers.IO).launch {
delay(10000)
runOnUiThread {
searchSpinner.setItems(arrayListOf("One"))
}
}




Expand Down

0 comments on commit 68ad6b2

Please sign in to comment.