Last active
March 5, 2018 04:55
-
-
Save droibit/1e212726ad9ba449427b to your computer and use it in GitHub Desktop.
ArrayAdapter<T>内の全Itemを取得するための拡張メソッド
This file contains hidden or 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
// ArrayAdapter.getItems() with iterator | |
public class ArrayAdapterIterator<T>(val adapter: ArrayAdapter<T>) { | |
private var index = 0 | |
fun next() = adapter.getItem(index++) | |
fun hasNext() = index < adapter.getCount() | |
} | |
public fun <T>ArrayAdapter<T>.iterator(): ArrayAdapterIterator<T> = ArrayAdapterIterator(this) | |
public fun <T>ArrayAdapter<T>.getItems(): List<T> { | |
val items = ArrayList<T>(getCount()) | |
for (item in this) { | |
items.add(item) | |
} | |
return items | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment