Last active
February 8, 2019 13:41
-
-
Save kibotu/e7e49918524b5f21448d7da475dde36e to your computer and use it in GitHub Desktop.
Spinner & kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<Spinner | |
android:id="@+id/picker" | |
android:layout_width="wrap_content" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
android:layout_height="wrap_content"/> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestFragment : Fragment(), AdapterView.OnItemSelectedListener { | |
override fun onNothingSelected(parent: AdapterView<*>?) { | |
Logger.v(TAG, "onItemSelected onNothingSelected") | |
} | |
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | |
Logger.v(TAG, "onItemSelected position=$position") | |
} | |
private val endPointSelectionListener = object : AdapterView.OnItemSelectedListener { | |
override fun onNothingSelected(parent: AdapterView<*>?) { | |
Logger.v(TAG, "onItemSelected onNothingSelected") | |
} | |
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | |
Logger.v(TAG, "onItemSelected position=$position") | |
} | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | |
return inflater.inflate(R.layout.fragment_test, container, false) | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
logv("onItemSelected set") | |
val adapter = ArrayAdapter.createFromResource(context, R.array.endpoints, android.R.layout.simple_spinner_item) | |
picker.adapter = adapter | |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | |
// endpoint_picker.onItemSelectedListener = this | |
picker.onItemSelectedListener = endPointSelectionListener | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment