android-fragments

Viewpager2 and Fragments

拟墨画扇 提交于 2021-02-05 07:14:07
问题 ViewPager2 does not support direct child views I'm trying to transition between fragments using the following code but I get the above error when using viewpager2. Call in fragment 1 to transition to fragment 2: getFragmentManager().beginTransaction().replace(R.id.viewPager2, new q2_fragment()).addToBackStack(null).commit(); Viewpager2 XML in Main Layout: <androidx.viewpager2.widget.ViewPager2 android:id="@+id/viewPager2" android:layout_width="match_parent" android:layout_height="match_parent

Viewpager2 and Fragments

a 夏天 提交于 2021-02-05 07:11:06
问题 ViewPager2 does not support direct child views I'm trying to transition between fragments using the following code but I get the above error when using viewpager2. Call in fragment 1 to transition to fragment 2: getFragmentManager().beginTransaction().replace(R.id.viewPager2, new q2_fragment()).addToBackStack(null).commit(); Viewpager2 XML in Main Layout: <androidx.viewpager2.widget.ViewPager2 android:id="@+id/viewPager2" android:layout_width="match_parent" android:layout_height="match_parent

Navigation drawer unlock mode ignored

眉间皱痕 提交于 2021-02-04 08:23:30
问题 So I have this app with one activity ( MainActivity ) and I'm using the navigation architecture component. So it has DrawerLayout which is wrapping the fragment view. These are two methods in the Activity class which are responsible for Locking and Unlocking of the drawerLayout . ... fun lockNavDrawer() { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) } fun unLockNavDrawer() { drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) } ... There are some fragments

How is Android Studio Navigation Drawer navigating different Fragments?

房东的猫 提交于 2021-02-02 09:33:25
问题 I've been trying to figure out how the default Navigation Drawer Activity template came with Android Studio navigates between different fragments. I understand that this menu is an implementation using AndroidX navigation component and navigation graph, but I just cannot understand how each menu item is mapped to its corresponding fragment. I don't see any listener or onNavigationItemSelected() etc. Can someone explain how the mapping between menuItem and corresponding fragment was achieved?

Android UI testing: Why LiveData's observers are not being called?

柔情痞子 提交于 2021-01-29 16:17:35
问题 I have been trying, without success, to do some UI tests on Android. My app follows the MVVM architecture and uses Koin for DI. I followed this tutorial to properly set up a UI test for a Fragment with Koin, MockK and Kakao. I created the custom rule for injecting mocks, setup the ViewModel, and on the @Before call, run the expected answers and returns with MockK. The problem is that, even when the fragment's viewmodel's LiveData object is the same as the testing class's LiveData object, the

Why is it necessary to implement OnFragmentInteractionListener when setting up a fragment?

守給你的承諾、 提交于 2021-01-29 13:55:05
问题 I followed the official documentation: https://developer.android.com/guide/components/fragments#Creating. It provides the steps to set up a fragment. First, create the fragment class (`extends Fragment') Then create its layout (and, in fragment class' OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) , return one of the View' of this layout using inflate`) Choose an activity that will use this fragment. This activity must extends FragmentActivity and in

Back button behaviour on activity to fragment in bottom navigation view

浪尽此生 提交于 2021-01-29 11:05:14
问题 I have a bottomnavigationview containing 5 fragments,(Consider A(Home), B, C, D, E) If I go to fragment D and then an Activity (Which is inside fragment D or C or any of 5) and press back button of the device. It is directly going to Home fragment(A), actually, it should go to fragment D or C. I have used botomnavigationview in my previous project but all things were working fine. Happening-- MainActivity+HomeFragment (A)---> Fragment D-->>Activity--->>OnbackPressed--->>HomeFragment Expected-

Previous fragment is restarting when we go back to previous fragment using backstack in android

瘦欲@ 提交于 2021-01-29 10:09:15
问题 lets say we have two fragment and we are in second fragment then if someone press back button then we successfully go back to the previous fragment (i.e. first fragment) using backstack but the problem is that the previous fragment is restarting everything. I want to display content of previous fragment without any restarting or initializing when we press back button.Thanks in advance. 回答1: Welcome to Android Fragment Life !! As suggested by @Uuu Uuu, you need to use add() method while adding

Tabs of Tab Layout don't display anything

时光怂恿深爱的人放手 提交于 2021-01-29 09:46:07
问题 This code is to create 3 tabs, made from fragments, that contains an image and text explanation, each one of them, to it. There's an obstacle on which the tabs don't display anything at all, all 3 of them. Here is the main code : public class Cookings extends AppCompatActivity { private TabLayout tabLayout; private ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cookings); tabLayout =

Adapter not found skipped in fragment with navigation drawer and appbar

帅比萌擦擦* 提交于 2021-01-29 09:45:59
问题 I make a fragment in which I attach a recycler view with dummy data but when I include this fragment in my slide up a panel which is in the main activity so the main activity slider data show but in fragment data it says recyclerview adapter not found it's skipped. kindly tell me what is an issue Main activity with Slidepanel layout.xml <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:sothree="http://schemas.android.com/apk/res