fragmentmanager

How to call fragment method from main activity

[亡魂溺海] 提交于 2019-11-30 11:38:51
问题 I have method in fragment class. I want to call that method from main activity but I don't want to use FragmentById (or) FragmentByTag. My fragment method: public void setItemFromDrawer(String sourceTag, String destTag) { //dosomething } How to call above method from main activity without using FragmentById (or) FragmentByTag? 回答1: First create an interface public interface MyInterface { void myAction() ; } Your fragment must implement this interface. public MyFragment extends Fragment

Android - Creating Multiple Levels of Tabs for ActionBar Using ViewPager and FragmentStatePagerAdapter

我与影子孤独终老i 提交于 2019-11-30 08:52:55
问题 How can I handle Android tabs in an ActionBar such that it presents multiple contextual levels of tabs and associated fragments to the user (in other words, I want the ActionBar tabs to change from one level to another based on the selections at the higher level - sort of like a hierarchical menu). (Ideally, the solution would support an arbitrary number of "levels", but at least three "levels" would be nice) NOTE: For proper order to the answers, sort by "oldest" - this puts the parts in the

FragmentManager popBackStack doesn't remove fragment

☆樱花仙子☆ 提交于 2019-11-30 05:15:11
I'm implementing menu navigation using Fragments. So I begin with Home, and then users can navigate to diferent sections and details of each section. When a user changes section, then I call pop on the fragmentmanager backstack until I reach Home, and then load the new section. This is all working as expected. But I'm getting this problem: load a section that calls setHasOptionsMenu(true) on onResume() loads another section (old section it's suposed to get out of the stack). I see it OK. No menu is shown leave the application (for example, go to Android Laucher activity) and then when I return

An invisible layout behind the fragment is getting clicked:

≡放荡痞女 提交于 2019-11-30 00:57:54
问题 I have created several fragments and I add the first fragment the following way: mainFragment = (MainFragment) MainFragment.create(); getSupportFragmentManager().beginTransaction() .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right) .add(R.id.content, mainFragment, MAIN_FRAGMENT_TAG) .commit(); The second fragment is added this way: getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_right, R.anim

How to call fragment method from main activity

末鹿安然 提交于 2019-11-30 00:39:48
I have method in fragment class. I want to call that method from main activity but I don't want to use FragmentById (or) FragmentByTag. My fragment method: public void setItemFromDrawer(String sourceTag, String destTag) { //dosomething } How to call above method from main activity without using FragmentById (or) FragmentByTag? First create an interface public interface MyInterface { void myAction() ; } Your fragment must implement this interface. public MyFragment extends Fragment implements MyInterface In your activity, define a field of type MyInterface : private MyInterface listener ;

Android - Creating Multiple Levels of Tabs for ActionBar Using ViewPager and FragmentStatePagerAdapter

为君一笑 提交于 2019-11-29 08:53:26
How can I handle Android tabs in an ActionBar such that it presents multiple contextual levels of tabs and associated fragments to the user (in other words, I want the ActionBar tabs to change from one level to another based on the selections at the higher level - sort of like a hierarchical menu). (Ideally, the solution would support an arbitrary number of "levels", but at least three "levels" would be nice) NOTE: For proper order to the answers, sort by "oldest" - this puts the parts in the right place with the HomeActivity last. Part 2... public void selectUpLayout() { try { if((appContext

FragmentTransaction hide/show doesn't work sometimes

丶灬走出姿态 提交于 2019-11-29 04:13:21
I have an activity with bottom navigation tabs that are changing the fragments in it. When I click back and forth on those tabs, at some point it stops working. Code executes just fine as I put some logs in it. But the fragments aren't being switched. Code is in kotlin but it's rather straight forward fun showTabFragment(tag: String) { val currentFragment: Fragment? = supportFragmentManager.fragments?.lastOrNull() var fragment = supportFragmentManager.findFragmentByTag(tag) val fragmentExists = fragment != null if (fragment == null) { when (tag) { TAG_LOGBOOK -> fragment = LogbookFragment()

IllegalStateException Fragment already added - Android

淺唱寂寞╮ 提交于 2019-11-28 14:36:19
I am adding fragment like bellow : @OnClick(R.id.lnNews) void newsList() { String tagName = returnStatusFragment(getString(R.string.news_list_fragment)); if (!TextUtils.isEmpty(tagName) && tagName.equals(getString(R.string.news_list_fragment))) { frameWorkTableFragment.setVisibility(View.VISIBLE); if (getActivity() != null) { android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); Fragment news = fragmentManager.findFragmentByTag(getString(R.string.news_list_fragment)); getActivity().getSupportFragmentManager().beginTransaction() .replace(R.id.frame

Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)

送分小仙女□ 提交于 2019-11-28 06:44:30
For some reason when I try to show a Dialog I get an error from dialog.show(fm, DIALOG_DATE); saying Cannot resolve method 'show(android.support.v4.app.FragmentManager, java.lang.String)' Why can't it resolve the method? mDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = new DatePickerFragment(); dialog.show(fm, DIALOG_DATE); } }); Here is the rest of my class: package com.bignerdranch.android.criminalintent; import android.os.Bundle; import android.support.v4.app

Fragment must be a public static class to be properly recreated from instance state

守給你的承諾、 提交于 2019-11-27 23:37:00
After updating to the latest support repository, compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:design:24.2.0' compile 'com.android.support:percent:24.2.0' compile 'com.android.support:recyclerview-v7:24.2.0' I'm getting the weird exception. java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:414) at android.support.v4.app.DialogFragment.show