android-fragments

access parent fragment by child fragment

佐手、 提交于 2020-08-21 07:59:28
问题 this is my child fragment and how to access my parent fragment from this fragment please help me to fix it public class Profilefragmant extends Fragment { public Profilefragment(){} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.profile_layout, container, false); TextView VE = (TextView) rootView.findViewById(R.id.profile_view_enquiry); VE.setOnClickListener(new View.OnClickListener(){

FragmentManager and androidx FragmentManager

天大地大妈咪最大 提交于 2020-08-21 07:39:30
问题 I'm trying to setup in my app that is using androidX. My problem is that when I try to work with PlaceAutocompleteFragment I get errors because it is a fragment from android.app.fragment and my parent fragment is an androidx fragment: androidx.fragment.app.Fragment so it uses a androidx.fragment.app.FragmentManager instead of a android.app.FragmentManager . How can I work with "old" fragments in androidX? 回答1: Add this to dependencies: implementation 'androidx.appcompat:appcompat:1.0.2' . Add

Custom “navigate up” behavior for certain fragment using Navigation component

南笙酒味 提交于 2020-08-21 05:14:13
问题 I want to add custom up navigation from fragment using Navigation component In my build.gradle(app) I use androidx.appcompat:appcompat:1.1.0-alpha04 dependency to have access to onBackPressedDispatcher from activity. So I implemented OnBackPressedCallback in my fragment and registered callback to dispatcher: requireActivity().onBackPressedDispatcher.addCallback(this) I expected that pressing navigate up in toolbar will call it, but it doesn't. Pressing device's back button calls it as

Custom “navigate up” behavior for certain fragment using Navigation component

馋奶兔 提交于 2020-08-21 05:13:46
问题 I want to add custom up navigation from fragment using Navigation component In my build.gradle(app) I use androidx.appcompat:appcompat:1.1.0-alpha04 dependency to have access to onBackPressedDispatcher from activity. So I implemented OnBackPressedCallback in my fragment and registered callback to dispatcher: requireActivity().onBackPressedDispatcher.addCallback(this) I expected that pressing navigate up in toolbar will call it, but it doesn't. Pressing device's back button calls it as

How to access parent Activity View in Fragment

落花浮王杯 提交于 2020-08-20 18:26:42
问题 I have an ActionBarActivity and fragment. I am using FragmentPagerAdapter that provides fragment to my app. My question How can I access parent Activity View in Fragment ?? 回答1: You can use View view = getActivity().findViewById(R.id.viewid); Quoting docs Specifically, the fragment can access the Activity instance with getActivity() and easily perform tasks such as find a view in the activity layout 回答2: At first, create a view like this: View view = getActivity().findViewById(R.id.viewid);

Android ViewPager2 FragmentStateAdapter shows Menu from every Fragment

守給你的承諾、 提交于 2020-08-20 14:22:11
问题 i have an activity with bottom navigation view with 3 Fragments associated. One of them is a Fragment with a ViewPager2 that uses a FragmentStateAdapter. Inside the createfragment(int position) method of the Adapter I return a couple Instances of another Fragment which has an Options Menu and inside it's onCreate() i call setHasOptionsMenu(true). The Problem is that on initialization of the adapter, the menu from all fragments are visible not just the menu of the currently visible fragment.

Fragments not added to backstack using Navigation Components

陌路散爱 提交于 2020-08-19 04:49:23
问题 Information: I'm programmatically inserting a NavHostFragment for each feature of the app. Each NavHostFragment has it's own Navigation Graph. Dagger is providing them by using a FragmentFactory specific to each feature. It's a Single Activity structure with MVVM architecture. Repo: https://github.com/mitchtabian/DaggerMultiFeature/tree/nav-component-backstack-bug checkout the branch "nav-component-backstack-bug". The Problem When navigating into the graph the fragments are not being added to

Fragments not added to backstack using Navigation Components

我与影子孤独终老i 提交于 2020-08-19 04:49:13
问题 Information: I'm programmatically inserting a NavHostFragment for each feature of the app. Each NavHostFragment has it's own Navigation Graph. Dagger is providing them by using a FragmentFactory specific to each feature. It's a Single Activity structure with MVVM architecture. Repo: https://github.com/mitchtabian/DaggerMultiFeature/tree/nav-component-backstack-bug checkout the branch "nav-component-backstack-bug". The Problem When navigating into the graph the fragments are not being added to

Open different activities by clicking on different cards in CardView ,Recyclerview Fragment in Android studio

☆樱花仙子☆ 提交于 2020-08-10 23:01:07
问题 I have created a RecyclerView and added cards in fragment.I want to open different activities by clicking on different cards in CardView.But I am only able to open the same activity for all the cards.I searched different answers in StackOverFlow.But I couldn't. could you tell me how to solve this issue...? If you can give full code,I'm happy. Here are my codes... PDFFragment.java public class PDFFragment extends Fragment { View v; List<Pdf> listBook; public View onCreateView(@NonNull

Open different activities by clicking on different cards in CardView ,Recyclerview Fragment in Android studio

自古美人都是妖i 提交于 2020-08-10 22:53:37
问题 I have created a RecyclerView and added cards in fragment.I want to open different activities by clicking on different cards in CardView.But I am only able to open the same activity for all the cards.I searched different answers in StackOverFlow.But I couldn't. could you tell me how to solve this issue...? If you can give full code,I'm happy. Here are my codes... PDFFragment.java public class PDFFragment extends Fragment { View v; List<Pdf> listBook; public View onCreateView(@NonNull