Skip to content
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

What is the bast way to handle DropDownPreference integer values #176

Closed
NLLAPPS opened this issue Oct 19, 2019 · 4 comments
Closed

What is the bast way to handle DropDownPreference integer values #176

NLLAPPS opened this issue Oct 19, 2019 · 4 comments
Labels

Comments

@NLLAPPS
Copy link

NLLAPPS commented Oct 19, 2019

I have a DropDownPreference with integer values. Android needs string-array for values to be used and that crates an issue where I have to define preference model member as var myPref: String by stringPref.

Is there a correct way of of accessing this preference apart from converting it to Int in my code?

@chibatching
Copy link
Owner

You can use pref value as the backing field of your value.

object Settings : KotprefModel() {
    private var internalMyPref: String by stringPref(key = "myPref")
    var myPref: Int
        get() = internalMyPref.toInt()
        set(value) {
            internalMyPref = value.toString()
        }
}

@NLLAPPS
Copy link
Author

NLLAPPS commented Oct 21, 2019 via email

@NLLAPPS
Copy link
Author

NLLAPPS commented Jan 6, 2020

Hi again, I don't suppose there is way to do above and observe with live-data.
Because myPref have no delegation, I get "failed to get preference key, check property 'pref' is delegated to Kotpref.'

Am I correct?

@chibatching
Copy link
Owner

Hi,

You are correct. Currently, Kotpref can't observe directly with LiveData.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants