[Q] Fragment null pointer after orientation change topic
Hi
I have a class Fragment_b extends Fragment with
frag_b_layout with root element of ScrollView containing a RelativeLayout with @+id/dummy for Android Studio ID sake.
in the container Activity
The problem is when the screen is rotated, fragment_b appears again but with fragment_b == null returns true, I was expecting
false. what can I do so that it works as I expect?
for no avail, I tried
in the AndroidManifest
in the onActivityCreated of fragment_b
Thank you
I have a class Fragment_b extends Fragment with
Code:
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frag_b_layout, container, false);
return view;
}
in the container Activity
Code:
public class MainActivity extends ActionBarActivity{
Fragment_b fragment_b;
FragmentManager manager;
//...
FragmentTransaction transaction = manager.beginTransaction();
public void myFunc(){
if (fragment_b == null){
fragment_b = new Fragment_b();
transaction.add(R.id.container_activity_layout, fragment_b, "someTag");
transaction.commit();
//...
}
}
//...
}
false. what can I do so that it works as I expect?
for no avail, I tried
in the AndroidManifest
Code:
android:windowSoftInputMode="stateUnchanged|adjustResize"
Code:
this.setRetainInstance(true);
xda-developers
0 commentaires:
Enregistrer un commentaire