Question

I am currently working on an android project where I need to create a SettingsActivity where I will have a variable number of checkboxes depending on an int from an SQLite database. I figured that the best way to do this was to create a for loop inside the SettingsActivity .java code, which would create a new checkbox preference for each time it runs the loop(as of now I only have a theoretical idea of how it would work). My problem would be to create the checkbox preference in .java rather than the XML. I searched the internet and could only find one example that had about 300 lines of code in it, and I can't believe that it needs to be as complicated as it was in that example. Does anyone have a helpful link, an idea how to do this or even knows a better way to make a variable number of checkboxes?

Sorry that I don't have any relevant code to post, but here is the link to the example I found http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/preference/CheckBoxPreference.java

Was it helpful?

Solution

http://developer.android.com/reference/android/preference/CheckBoxPreference.html It also inherits a lot of methods from Preference: http://developer.android.com/reference/android/preference/Preference.html. You can pass the constructor an attribute set where you specify summaryOn and summaryOff and the title

The link you posted is the source code of android. You don't need to implement that in your application as it's already in the android environment

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top