Skip to content

Instantly share code, notes, and snippets.

@nicoqueijo
Created May 15, 2020 01:25
Show Gist options
  • Save nicoqueijo/ee6a3c34a821a649ce119ec180d83755 to your computer and use it in GitHub Desktop.
Save nicoqueijo/ee6a3c34a821a649ce119ec180d83755 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private lateinit var scrollView: ScrollView
private lateinit var dragLinearLayout: DragLinearLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
scrollView = findViewById(R.id.scroll_view)
dragLinearLayout = findViewById<DragLinearLayout>(R.id.drag_linear_layout).apply {
setContainerScrollView(scrollView)
setOnViewSwapListener { _, startPosition, _, endPosition ->
swapElements(startPosition, endPosition)
}
}
...
}
...
private fun swapElements(startPosition: Int, endPosition: Int) {
addedCurrencies.run {
this[startPosition] = this[endPosition].also {
this[endPosition] = this[startPosition]
}
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment