android-fragments

How to handle rotate screen and save data in Fragment?

笑着哭i 提交于 2021-02-08 08:20:05
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

How to handle rotate screen and save data in Fragment?

拈花ヽ惹草 提交于 2021-02-08 08:17:24
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

Android - PageView in new BottomNavigationBar - prevent reload fragments

。_饼干妹妹 提交于 2021-02-08 04:43:23
问题 In my StartActivity the BottomNavigationBar Listener has the following setup: private GuideFragment guideFragment = new GuideFragment(); private MapFragment mapFragment = new MapFragment(); private MoreFragment moreFragment = new MoreFragment(); private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { Fragment

Dismiss a bottom sheet dialogue in android from its own Custom Activity

。_饼干妹妹 提交于 2021-02-08 03:00:58
问题 I have created a custom bottom sheet android dialogue with the help of this answer by Chintan Khetiya:How to create a Custom Dialog box in android?. I want to dismiss the dialogue from the button defined in the BottomDialogue's own Activity.Not from Calling activity. Here is my code in the Calling activity in which i have created my custom BottomSheet_liab instance by click of a button: openBottomDialogeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View

Dismiss a bottom sheet dialogue in android from its own Custom Activity

╄→尐↘猪︶ㄣ 提交于 2021-02-08 03:00:10
问题 I have created a custom bottom sheet android dialogue with the help of this answer by Chintan Khetiya:How to create a Custom Dialog box in android?. I want to dismiss the dialogue from the button defined in the BottomDialogue's own Activity.Not from Calling activity. Here is my code in the Calling activity in which i have created my custom BottomSheet_liab instance by click of a button: openBottomDialogeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View

What is difference between 'new Fragment()' and 'Fragment.getInstance()' in Android?

∥☆過路亽.° 提交于 2021-02-07 19:49:49
问题 In android programming, When we add fragment to specific layout, we can use folloing codes Fragment fragment = new SampleFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.content_layout, fragment); fragmentTransaction.commit(); or Fragment fragment = SampleFragment.getInstance(); FragmentManager fragmentManager = getSupportFragmentManager();

Disable clicks when fragment adding animation playing

☆樱花仙子☆ 提交于 2021-02-07 18:15:25
问题 I have a method, which perform a fragment adding animation and a new fragment fills all screen: public void addFragmentWithAnimation(Fragment fragment, boolean addToBackStack){ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_right); if (addToBackStack) { transaction.addToBackStack(null); } transaction.add(R.id.lay_fragments, fragment);

Using onPrepareOptionsMenu instead of onCreateOptionsMenu in Fragment

元气小坏坏 提交于 2021-02-07 12:30:38
问题 I had a problem setting up some fragment menu items in the ActionBar and I found a way to solve it, but I don't understand why it worked. I wanted to change the visibility in a menu item right after I inflated it from a menu xml file in onCreateOptionsMenu method. The code seems to work fine, but there's no visible effect. I solved the problem inflating the menu in onCreateOptionsMenu method but changing the visibility of it in onPrepareOptionsMenu method. What I want to know is why changing

Android Navigation Component : Pass value (arguments) in fragments

佐手、 提交于 2021-02-07 11:27:23
问题 What I have done: I have created Navigation Drawer Activity , As updated new format of Navigation Drawer Activity , As per new Android architecture, I got it with Navigation Component structure. The NavigationView code with NavController and NavigationUI as below which is opening fragment when I click on any navigation item. DrawerLayout drawer = findViewById(R.id.drawer_layout); NavigationView navigationView = findViewById(R.id.nav_view); // Passing each menu ID as a set of Ids because each

AndroidRuntimeException: requestFeature() must be called before adding content [duplicate]

你离开我真会死。 提交于 2021-02-07 05:35:13
问题 This question already has answers here : requestFeature() must be called before adding content (8 answers) Closed 6 years ago . I have dialog fragment. I have intention to use this fragment in activity and dialog. And I override onCreateDialog and onCreateView method. here is coding. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.interval_time_popup, null); setup(view, false); return view; }