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;
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
add a comment |
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
Why you define viewModel in onActivityCreated, define it onCreateView()?
– Asad Mukhtar
Apr 4 at 20:04
add a comment |
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
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
android-fragments android-databinding android-architecture-navigation
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 28 at 8:35
IvanIvan
1,4992 gold badges15 silver badges26 bronze badges
1,4992 gold badges15 silver badges26 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Why you define viewModel in onActivityCreated, define it onCreateView()?
– Asad Mukhtar
Apr 4 at 20:04