Created
May 15, 2020 01:25
-
-
Save nicoqueijo/ee6a3c34a821a649ce119ec180d83755 to your computer and use it in GitHub Desktop.
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
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