Android data binding makes fragment display full screen, breaks navigationHow to use data-binding with FragmentSend data from activity to fragment in AndroidSwitching between Android Navigation Drawer image and Up caret when using fragmentsMake fragments full screen programmaticallyHow to use data-binding with FragmentSuperNotCalledException after obfuscation with ProguardIssue with AutoCompleteTextView in a fragmnet used inside TabbedActivityHide android bottom navigation view for child screens/ fragmentsAndroid navigation component- With Login screensAndroid data binding to fragmentAndroid Navigation Component: prevent configChanges of single fragment

Why is the battery jumpered to a resistor in this schematic?

Would getting a natural 20 with a penalty still count as a critical hit?

Is there a way, other than having a Diviner friend, for a player to avoid rolling Initiative at the start of a combat?

Can I use my OWN published papers' images in my thesis without Copyright infringment

Problem with GFCI at start of circuit with both lights and two receptacles

If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?

Typesetting "hollow slash"

How do I answer an interview question about how to handle a hard deadline I won't be able to meet?

Why does Japan use the same type of AC power outlet as the US?

Why does "auf der Strecke bleiben" mean "to fall by the wayside"?

What is the question mark?

When does The Truman Show take place?

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

What is the fastest way to level past 95 in Diablo II?

What is the opposite of "hunger level"?

How do I pass a "list of lists" as the argument to a function of the form F[x,y]?

Adding things to bunches of things vs multiplication

Why do we use low resistance cables to minimize power losses?

Did Michelle Obama have a staff of 23; and Melania have a staff of 4?

Expressing a chain of boolean ORs using ILP

What was the intention with the Commodore 128?

Is the Microsoft recommendation to use C# properties applicable to game development?

Physical Interpretation of an Overdamped Pendulum

Unconventional examples of mathematical modelling



Android data binding makes fragment display full screen, breaks navigation


How to use data-binding with FragmentSend data from activity to fragment in AndroidSwitching between Android Navigation Drawer image and Up caret when using fragmentsMake fragments full screen programmaticallyHow to use data-binding with FragmentSuperNotCalledException after obfuscation with ProguardIssue with AutoCompleteTextView in a fragmnet used inside TabbedActivityHide android bottom navigation view for child screens/ fragmentsAndroid navigation component- With Login screensAndroid data binding to fragmentAndroid Navigation Component: prevent configChanges of single fragment






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I have a single activity app with bottom navigation tabs using Android Architecture Navigation Component.



Here is the code for one of the fragments:



public class ProfileFragment extends BaseFragment 

private final int layout = R.layout.fragment_profile;
//private final int layout = R.layout.fragment_profile_;

private ProfileViewModel mViewModel;
// FragmentProfileBinding mBinding;

public static ProfileFragment newInstance()
return new ProfileFragment();


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
return inflater.inflate(layout, container, false);


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);

// mBinding = DataBindingUtil.setContentView(getActivity(), layout);
// mBinding.setLifecycleOwner(this);
// mBinding.setVm(mViewModel);


@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

((mcApplication) getActivity().getApplication())
.getApplicationComponent()
.inject(this);




It has 2 possible versions (one which is with data binding is commented).



Current version without databinding works correctly, but the version with data binding displays fragment fullscreen instead of displaying it within the androidx.navigation.fragment.NavHostFragment area of my MainActivity.
Binding of data works, my problem is that fragment displays full screen and trying to programmatically navigate from this fragment does not work. So databinding in this case breaks things.
What am I doing wrong?



Here is contents of the fragment_profile_.xml file:



 <?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
<variable
name="vm"
type="com.synergy.megacampus3.viewmodel.ProfileViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@=vm.fullUserName"
android:textColor="@color/mc_text_color_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/avatar"
tools:textSize="16sp" />

</LinearLayout>
</layout>









share|improve this question
























  • Why you define viewModel in onActivityCreated, define it onCreateView()?

    – Asad Mukhtar
    Apr 4 at 20:04

















-1















I have a single activity app with bottom navigation tabs using Android Architecture Navigation Component.



Here is the code for one of the fragments:



public class ProfileFragment extends BaseFragment 

private final int layout = R.layout.fragment_profile;
//private final int layout = R.layout.fragment_profile_;

private ProfileViewModel mViewModel;
// FragmentProfileBinding mBinding;

public static ProfileFragment newInstance()
return new ProfileFragment();


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
return inflater.inflate(layout, container, false);


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);

// mBinding = DataBindingUtil.setContentView(getActivity(), layout);
// mBinding.setLifecycleOwner(this);
// mBinding.setVm(mViewModel);


@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

((mcApplication) getActivity().getApplication())
.getApplicationComponent()
.inject(this);




It has 2 possible versions (one which is with data binding is commented).



Current version without databinding works correctly, but the version with data binding displays fragment fullscreen instead of displaying it within the androidx.navigation.fragment.NavHostFragment area of my MainActivity.
Binding of data works, my problem is that fragment displays full screen and trying to programmatically navigate from this fragment does not work. So databinding in this case breaks things.
What am I doing wrong?



Here is contents of the fragment_profile_.xml file:



 <?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
<variable
name="vm"
type="com.synergy.megacampus3.viewmodel.ProfileViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@=vm.fullUserName"
android:textColor="@color/mc_text_color_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/avatar"
tools:textSize="16sp" />

</LinearLayout>
</layout>









share|improve this question
























  • Why you define viewModel in onActivityCreated, define it onCreateView()?

    – Asad Mukhtar
    Apr 4 at 20:04













-1












-1








-1








I have a single activity app with bottom navigation tabs using Android Architecture Navigation Component.



Here is the code for one of the fragments:



public class ProfileFragment extends BaseFragment 

private final int layout = R.layout.fragment_profile;
//private final int layout = R.layout.fragment_profile_;

private ProfileViewModel mViewModel;
// FragmentProfileBinding mBinding;

public static ProfileFragment newInstance()
return new ProfileFragment();


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
return inflater.inflate(layout, container, false);


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);

// mBinding = DataBindingUtil.setContentView(getActivity(), layout);
// mBinding.setLifecycleOwner(this);
// mBinding.setVm(mViewModel);


@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

((mcApplication) getActivity().getApplication())
.getApplicationComponent()
.inject(this);




It has 2 possible versions (one which is with data binding is commented).



Current version without databinding works correctly, but the version with data binding displays fragment fullscreen instead of displaying it within the androidx.navigation.fragment.NavHostFragment area of my MainActivity.
Binding of data works, my problem is that fragment displays full screen and trying to programmatically navigate from this fragment does not work. So databinding in this case breaks things.
What am I doing wrong?



Here is contents of the fragment_profile_.xml file:



 <?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
<variable
name="vm"
type="com.synergy.megacampus3.viewmodel.ProfileViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@=vm.fullUserName"
android:textColor="@color/mc_text_color_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/avatar"
tools:textSize="16sp" />

</LinearLayout>
</layout>









share|improve this question














I have a single activity app with bottom navigation tabs using Android Architecture Navigation Component.



Here is the code for one of the fragments:



public class ProfileFragment extends BaseFragment 

private final int layout = R.layout.fragment_profile;
//private final int layout = R.layout.fragment_profile_;

private ProfileViewModel mViewModel;
// FragmentProfileBinding mBinding;

public static ProfileFragment newInstance()
return new ProfileFragment();


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
return inflater.inflate(layout, container, false);


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);

// mBinding = DataBindingUtil.setContentView(getActivity(), layout);
// mBinding.setLifecycleOwner(this);
// mBinding.setVm(mViewModel);


@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

((mcApplication) getActivity().getApplication())
.getApplicationComponent()
.inject(this);




It has 2 possible versions (one which is with data binding is commented).



Current version without databinding works correctly, but the version with data binding displays fragment fullscreen instead of displaying it within the androidx.navigation.fragment.NavHostFragment area of my MainActivity.
Binding of data works, my problem is that fragment displays full screen and trying to programmatically navigate from this fragment does not work. So databinding in this case breaks things.
What am I doing wrong?



Here is contents of the fragment_profile_.xml file:



 <?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<data>
<variable
name="vm"
type="com.synergy.megacampus3.viewmodel.ProfileViewModel" />
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@=vm.fullUserName"
android:textColor="@color/mc_text_color_1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/avatar"
tools:textSize="16sp" />

</LinearLayout>
</layout>






android-fragments android-databinding android-architecture-navigation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 12:27









IvanIvan

1,4992 gold badges15 silver badges26 bronze badges




1,4992 gold badges15 silver badges26 bronze badges















  • Why you define viewModel in onActivityCreated, define it onCreateView()?

    – Asad Mukhtar
    Apr 4 at 20:04

















  • Why you define viewModel in onActivityCreated, define it onCreateView()?

    – Asad Mukhtar
    Apr 4 at 20:04
















Why you define viewModel in onActivityCreated, define it onCreateView()?

– Asad Mukhtar
Apr 4 at 20:04





Why you define viewModel in onActivityCreated, define it onCreateView()?

– Asad Mukhtar
Apr 4 at 20:04












1 Answer
1






active

oldest

votes


















0














My problem was that I initialized binding in the wrong place and wrong way.
The working code is this:



public static ProfileFragment newInstance() 
return new ProfileFragment();


@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);

((mcApplication) getActivity().getApplication())
.getApplicationComponent()
.inject(this);
mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);


@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)

mBinding = DataBindingUtil.inflate(
inflater, layout, container, false);
View view = mBinding.getRoot();
mBinding.setLifecycleOwner(this);
mBinding.setVm(mViewModel);

return view;


@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
super.onActivityCreated(savedInstanceState);




Code taken from here






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377217%2fandroid-data-binding-makes-fragment-display-full-screen-breaks-navigation%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    My problem was that I initialized binding in the wrong place and wrong way.
    The working code is this:



    public static ProfileFragment newInstance() 
    return new ProfileFragment();


    @Override
    public void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);

    ((mcApplication) getActivity().getApplication())
    .getApplicationComponent()
    .inject(this);
    mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState)

    mBinding = DataBindingUtil.inflate(
    inflater, layout, container, false);
    View view = mBinding.getRoot();
    mBinding.setLifecycleOwner(this);
    mBinding.setVm(mViewModel);

    return view;


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState)
    super.onActivityCreated(savedInstanceState);




    Code taken from here






    share|improve this answer





























      0














      My problem was that I initialized binding in the wrong place and wrong way.
      The working code is this:



      public static ProfileFragment newInstance() 
      return new ProfileFragment();


      @Override
      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);

      ((mcApplication) getActivity().getApplication())
      .getApplicationComponent()
      .inject(this);
      mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);


      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState)

      mBinding = DataBindingUtil.inflate(
      inflater, layout, container, false);
      View view = mBinding.getRoot();
      mBinding.setLifecycleOwner(this);
      mBinding.setVm(mViewModel);

      return view;


      @Override
      public void onActivityCreated(@Nullable Bundle savedInstanceState)
      super.onActivityCreated(savedInstanceState);




      Code taken from here






      share|improve this answer



























        0












        0








        0







        My problem was that I initialized binding in the wrong place and wrong way.
        The working code is this:



        public static ProfileFragment newInstance() 
        return new ProfileFragment();


        @Override
        public void onCreate(Bundle savedInstanceState)
        super.onCreate(savedInstanceState);

        ((mcApplication) getActivity().getApplication())
        .getApplicationComponent()
        .inject(this);
        mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);


        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState)

        mBinding = DataBindingUtil.inflate(
        inflater, layout, container, false);
        View view = mBinding.getRoot();
        mBinding.setLifecycleOwner(this);
        mBinding.setVm(mViewModel);

        return view;


        @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState)
        super.onActivityCreated(savedInstanceState);




        Code taken from here






        share|improve this answer













        My problem was that I initialized binding in the wrong place and wrong way.
        The working code is this:



        public static ProfileFragment newInstance() 
        return new ProfileFragment();


        @Override
        public void onCreate(Bundle savedInstanceState)
        super.onCreate(savedInstanceState);

        ((mcApplication) getActivity().getApplication())
        .getApplicationComponent()
        .inject(this);
        mViewModel = ViewModelProviders.of(this, viewModelFactory).get(ProfileViewModel.class);


        @Override
        public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState)

        mBinding = DataBindingUtil.inflate(
        inflater, layout, container, false);
        View view = mBinding.getRoot();
        mBinding.setLifecycleOwner(this);
        mBinding.setVm(mViewModel);

        return view;


        @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState)
        super.onActivityCreated(savedInstanceState);




        Code taken from here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 8:35









        IvanIvan

        1,4992 gold badges15 silver badges26 bronze badges




        1,4992 gold badges15 silver badges26 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377217%2fandroid-data-binding-makes-fragment-display-full-screen-breaks-navigation%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript