I started dealing with preferences in a PreferenceFragment
. Here\'s what I have:
Had totally forgot about this question, will post an answer now to help others. I solved by moving my code in the onResume()
method of the activity that hosts my PreferenceFragment
. I think there are several other points at which you can recall a non-null ListView
using findViewById(android.R.id.list)
.
public boolean mListStyled;
@Override
public void onResume() {
super.onResume();
if (!mListStyled) {
View rootView = getView();
if (rootView != null) {
ListView list = (ListView) rootView.findViewById(android.R.id.list);
list.setPadding(0, 0, 0, 0);
list.setDivider(null);
//any other styling call
mListStyled = true;
}
}
}
You can probably get rid of the rootView
check, but at the same time you might even want to check for list != null
. I didn't face any NPE this way anyway.
So, setDivider(null)
takes off the item-item dividers. I managed to add section dividers covering the full width of the screen by:
list
;n