Reputation: 33966
I had recently had to do add a view to a LinearLayout programatically, I have to do the same for a for a PreferenceScreen but I don't know how. This is how it was done for a LinearLayout:
LayoutInflater localLayoutInflater = (LayoutInflater)getBaseContext().getSystemService("layout_inflater");
View myView = localLayoutInflater.inflate(R.layout.custom_layout, null);
final PreferenceScreen ll=(LinearLayout)findViewById(R.id.linearlayoutID);
ll.addView(myView);
How can I do the same to add a preference to a PreferenceScreen?
EDIT:
This is what I've done so far:
Preference preference = new Preference(this);
preference .setTitle("WHATEVER");
preference .setSummary("Summary");
preference .setKey("your_key");
I managed to create a preference and store it in list1, I think it's ok so far, but now I need to figure out how to append it inside <PreferenceScreen id="@+id/list">
?
Upvotes: 1
Views: 147
Reputation: 115952
try this:
PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("containerId");
if (preferenceGroup != null) {
preferenceGroup.addPreference(myNewPreference);
}
same goes for PreferenceScreen (replace PreferenceScreen with each time i've written PreferenceGroup ).
Upvotes: 1