J
J
JonathanImmo2015-06-25 16:37:27
Android
JonathanImmo, 2015-06-25 16:37:27

Android, why can't set a fragment from a variable?

Hello, I have a problem, my phone shows a black screen when I try to insert my class object into FragmentTransaction

LoginFragment lf = new LoginFragment();
fTrans = getFragmentManager().beginTransaction();
fTrans.add(R.id.loginContainer, lf).commit();

But if I add an instance of the class, then everything works fine
fTrans = getFragmentManager().beginTransaction();
fTrans.add(R.id.loginContainer,
    new LoginFragment()).commit();

The problem is that I'm trying to do this on my LG, which is 4.0.3, and on 4.2.2 and above everything works fine. Please tell me what is causing this bug.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin, 2015-06-25
Kiriushyn @KonstantinKiriushyn

At first glance, everything should work. If specific to version 4.0.3, or device specific, make sure to use the support library classes.

R
Ruslan Yudin, 2015-06-25
@deleted-Ruslan80849

What if Fragment login = new LoginFragment();?

N
Neic, 2015-06-25
@thomas_white

Try using replace instead of add.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question