Programatically add a preference, with other preferences in xml file:
Other solutions didn't work for me because I ALSO had an xml with preferences. I'm not sure all these calls are necessary/redundant, but this works.
onCreate() method, class extends PreferenceActivity:
setContentView(R.layout.preferences);
addPreferencesFromResource(R.xml.preferences);
PreferenceScreen pScreen = getPreferenceManager().createPreferenceScreen(this);
CheckBoxPreference cb = new CheckBoxPreference(this);
cb.setKey("cb");
cb.setTitle("BLAH");
cb.setOrder(99); //not working...
pScreen.addPreference(cb);
setPreferenceScreen(pScreen);
addPreferencesFromResource(R.xml.preferences);
Sidenote: Since I needed to generate a dynamic checkbox list, it was best suited inside an inner PreferenceScreen. So I created this PreferenceScreen inside the xml, then dynamically generated the checkboxes inside this. This way the ordering didn't matter since all the 'new' dynamica checkboxes were inside this screen.