I managed to write a method that's actually quite simple and without need for invalidating ListViews or or whatever the situation may be. This method makes a call to the public ViewGroup removeView(View view)
, View requestLayout()
, View forceLayout()
, ViewGroup addView(View view)
, and finally a call to Fragment OnCreate(Bundle savedInstanceState)
methods with a few null checks and a final View
temporary variable to store the actual view when the view is removed.
This method is still quite new and I'll be giving it some tweaking and refining over the next 2 days but it works flawlessly as is with no whack side effects. Since the class I've written holding the code changes the actual preference title and summary text styles for the whole rom (that was the whole point to the options I've added), I've also added a public constructor the classes that are activities that lie in the activity stack below the preference style screen so they can be updated at the same time. Most likely I will be moving this new method into the frameworks view class so it can be made available system wide.
public void reLoadView(View view) {
if (view == null) {
view = mView;
Log.i(TAG, "The current View is: " + view);
}
final View tmpView = view;
try {
setStyleChanged(1);
setReset(0);
Log.i(TAG, "The Temporary View is: " + tmpView);
Log.i(TAG, "The current View is: " + mView);
Log.i(TAG, "The current ViewGroup is: " + mViewGroup);
if (mView != null) {
if (mViewGroup != null) {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
mViewGroup.removeView(mView);
mView.requestLayout();
mView.forceLayout();
mViewGroup.addView(tmpView);
onCreate(new Bundle());
}
});
}
}
View tmp = null;
mDemented.reLoadView(tmp);
} catch (Exception e) {
}
}
The view variables themselves are set initially in the class initialization and are initialized and defined in the View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
and the View onViewCreated(View view, Bundle savedInstanceState)
. The view variables themselves are set initially in the class initialization.
private View mView;
private ViewGroup mViewGroup;
private int mLayoutResId = R.layout.preference_list_fragment;//holds the layout reference just to keep it clean
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View rootView = inflater.inflate(mLayoutResId, parent, false);
mViewGroup = parent;
return rootView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mView = view;
}
In the activities in the stack below, my PreferenceStyle class, I set an empty constructor which can be initialized anywhere in the app.
public class DEMENTED extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, View.OnClickListener {
public DEMENTED() {
super();
}
//other code to do whatever here
In my PreferenceStyle class I imported my DEMENTED class then set it as a variable prior to onCreate(Bundle savedInstanceState)
:
private DEMENTED mDemented;
Then initialized the variable in onCreate(Bundle savedInstanceState)
:
mDemented = new DEMENTED();
The call to my DEMENTED class to reload its view is done in my reloadView(View view)
method but the variable view used to make the call is a View variable set immediately prior to the call and is set as null:
View tmp = null;
mDemented.reLoadView(tmp);
and my DEMENTED class checks to see if the included View in the method call is null and if so sets it to a localized View variable so the method can do its work with local variables:
public void reLoadView(View view) {
if (view == null) {
view = mView;
Log.i(TAG, "The current View is: " + view);
}
//all the other good stuff here
Basically, this uses the ViewGroup as defined in onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
:
mViewGroup = parent;
and View variable is set in onViewCreated(View view, Bundle savedInstanceState)
mView = view;
Hope this helps someone out because this has been a question I've seen repeated on here over and over and I have yet to find a solid solution basically anywhere that didn't involve multiple classes used as utils. If anyone has any comment suggestions to simplify or whatever feel free to comment.