-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save selected item and position #1
Comments
There are multiple ways, it can be done in one of the callbacks, you will need to add the unique identifier of the selected item (needs to be the field of your Model) in the preference and then later extract it, given this item's list is already stored somewhere. Another way is to use some kind of Json parser framework like Gson or Moshi to convert the model to jsontString save that string and then when you read that string from preference convert it back to your model. For this example I am putting all the selected items in In this example there is a interface callback which is provided to override fun onDrag(v: View?, event: DragEvent): Boolean {
val state = event.localState as DragData
when (event.action) {
DragEvent.ACTION_DRAG_ENTERED -> {
binding.rvSelectedSetting.setBackgroundResource(R.drawable.green_dashed_box)
}
DragEvent.ACTION_DRAG_EXITED -> {
binding.rvSelectedSetting.setBackgroundResource(R.drawable.dashed_box)
}
DragEvent.ACTION_DRAG_ENDED -> {
binding.rvSelectedSetting.setBackgroundResource(R.drawable.dashed_box)
}
DragEvent.ACTION_DROP -> {
if (listItemSelected.find { it.id == state.item.id } != null) {
Toast.makeText(MainActivity@ this, "Setting already exists!", Toast.LENGTH_LONG)
.show()
return true
}
listItemSelected.add(0, state.item) // All the selected items getting stored in this list.
selectedSettingAdapter.notifyItemRangeInserted(0, 1)
}
else -> {}
}
return true
} |
How can i save selected item and positon with shared preferences?
thank you
The text was updated successfully, but these errors were encountered: