android-fragments

onActivityCreated is deprecated, how to properly use LifecycleObserver?

久未见 提交于 2020-08-04 06:01:47
问题 Google deprecate fragment’s onActivityCreated() on Android and recommend to use LifeCycleObserver: To get a callback specifically when a Fragment activity's * {@link Activity#onCreate(Bundle)} is called, register a * {@link androidx.lifecycle.LifecycleObserver} on the Activity's * {@link Lifecycle} in {@link #onAttach(Context)}, removing it when it receives the * {@link Lifecycle.State#CREATED} callback. So I try to make it in recommended way, but only state I can observe in Logcat is just

E/RecyclerView: No adapter attached; skipping layout (Using FRAGMENTS)

旧城冷巷雨未停 提交于 2020-08-03 09:14:08
问题 I modified my code according to the answers I found to similar questions but none of them worked. I am using TabFragments and RecyclerViews. The console displays the error "E/RecyclerView: No adapter attached; skipping layout" four times. (When modifying it also gave me the error "java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference",

How to pass arguments to a fragment using bottom navigation view and Android Navigation component?

血红的双手。 提交于 2020-08-02 06:17:48
问题 Is it possible to pass and access arguments in a fragment using a bottom navigation view and the Navigation component? I'm using a one activity with many fragments approach where my top level fragment requires an argument(Usually done via the newInstance generated method). I've had a look at the Navigation component developer guide and the codelab but it only mentions using safeargs and adding argument tags in the destinations and actions. Here's my navigation graph: <navigation xmlns:app=

How to use the Android Navigation component (Nav Graph) in a Drawer Layout (with navigation drawer Menu)?

旧时模样 提交于 2020-07-31 03:48:52
问题 I have a navigation graph that uses this fragment as a home in the main activity XML. <fragment android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" class="androidx.navigation.fragment.NavHostFragment" app:navGraph="@navigation/main_nav_graph" app:defaultNavHost="true"/> I have a Drawer layout with a menu , I can't manage to make the navigation to work when I click on the

How to use the Android Navigation component (Nav Graph) in a Drawer Layout (with navigation drawer Menu)?

你离开我真会死。 提交于 2020-07-31 03:47:28
问题 I have a navigation graph that uses this fragment as a home in the main activity XML. <fragment android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" class="androidx.navigation.fragment.NavHostFragment" app:navGraph="@navigation/main_nav_graph" app:defaultNavHost="true"/> I have a Drawer layout with a menu , I can't manage to make the navigation to work when I click on the

How to use the Android Navigation component (Nav Graph) in a Drawer Layout (with navigation drawer Menu)?

那年仲夏 提交于 2020-07-31 03:47:11
问题 I have a navigation graph that uses this fragment as a home in the main activity XML. <fragment android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" class="androidx.navigation.fragment.NavHostFragment" app:navGraph="@navigation/main_nav_graph" app:defaultNavHost="true"/> I have a Drawer layout with a menu , I can't manage to make the navigation to work when I click on the

How to scope a view model to a parent fragment?

╄→гoц情女王★ 提交于 2020-07-30 05:57:08
问题 So I'm using the new navigation component (with the one activity principle) and communicating between each fragment using shared view models, however, I've come to a point where I sometimes need to clear the view model but I can't find a good place to clear it. But tbh I think rather than trying to clear it myself, I should really be allowing the framework to do it for me, but it doesn't because the view models are shared and scoped to the activity, but I think I can scope them to a parent

How to scope a view model to a parent fragment?

旧时模样 提交于 2020-07-30 05:55:00
问题 So I'm using the new navigation component (with the one activity principle) and communicating between each fragment using shared view models, however, I've come to a point where I sometimes need to clear the view model but I can't find a good place to clear it. But tbh I think rather than trying to clear it myself, I should really be allowing the framework to do it for me, but it doesn't because the view models are shared and scoped to the activity, but I think I can scope them to a parent

How to fix MainActivity cannot be cast to android.app.TimePickerDialog$OnTimeSetListener in a fragment?

◇◆丶佛笑我妖孽 提交于 2020-07-23 06:55:06
问题 i'm doing my school project in android since days ago, and I got a problem today. I did a menu with fragments and I need to put a TimePickerDialog inside a fragment and for me it's impossible, everytime when I press the button lo launch the Dialog the app crashes. I try to put implements in the class of the TimePickerFragment but it doens't work, I need to bring the things in my main fragment, not in the Dialog. Here is my main fragment, called "DespertarFragment": @Override public View

How to fix MainActivity cannot be cast to android.app.TimePickerDialog$OnTimeSetListener in a fragment?

∥☆過路亽.° 提交于 2020-07-23 06:54:05
问题 i'm doing my school project in android since days ago, and I got a problem today. I did a menu with fragments and I need to put a TimePickerDialog inside a fragment and for me it's impossible, everytime when I press the button lo launch the Dialog the app crashes. I try to put implements in the class of the TimePickerFragment but it doens't work, I need to bring the things in my main fragment, not in the Dialog. Here is my main fragment, called "DespertarFragment": @Override public View