Questions tagged [fragment]

**DO NOT USE**: fragment is an ambiguous tag, used to refer to numerous technologies. Prefer less ambiguous tags. For Android Fragments, use [android-fragments]. For URL fragments, use [url-fragment]

'fragment' Tag Disambiguation

8161 questions
65
votes
6 answers

How to determine fragment restored from backstack

Been searching for this issue for a while to no avail now: How to determine fragment is being restored from backstack? I'm using the compatibility library and a ListFragment inside a FragmentActivity. When an item inside ListFragment is selected, a…
dvd
  • 1,470
  • 1
  • 16
  • 24
64
votes
10 answers

Get the Application Context In Fragment In Android?

I have stored some data to a Global Class By using the Application Context In One Activity. Later I have to Retrieve those values in A Fragment. I have done something like this to store in Global Class. AndroidGlobalClass AGC =…
NRahman
  • 2,717
  • 5
  • 24
  • 29
62
votes
8 answers

How to start shared element transition using Fragments?

I am trying to implement transitions between fragments which have "shared elements" as described in the new material design specs. The only method I can find is the ActivityOptionsCompat.makeSceneTransitionAnimation, which I believe works on…
unchosen
  • 874
  • 1
  • 12
  • 14
57
votes
14 answers

Cannot resolve method 'getSupportFragmentManager ( )' inside Fragment

I found the message Cannot resolve method 'getSupportFragmentManager ( )' I want to fragment as activity. because I want to use Maps on the tabs swipe. public class PETAcikarangsukatani extends Fragment { Context context; private static final…
Irwans
  • 583
  • 1
  • 4
  • 4
56
votes
11 answers

Fragment already added IllegalStateException

I use this method on my container Activity to show a BFrag public void showBFrag() { // Start a new FragmentTransaction FragmentTransaction fragmentTransaction = mFragmentMgr.beginTransaction(); if(mBFrag.isAdded()) { …
56
votes
5 answers

How do I start an activity from within a Fragment?

I have a set of tabs inside of a FragmentActivity that each hold their own fragment. When I tried to start a new activity from within that fragment via an onClickListener, and using the startActivity(myIntent) method, my application force…
user1617134
55
votes
5 answers

Preventing the back button from cancelling a DialogFragment

I have a Fragment that can create and pop up a DialogFragment, but when I hit the back button, it dismisses the dialog even though I explicitly call setCancelable(false); Is there any way for my DialogFragment to be insensative to the back…
MattF
  • 1,475
  • 3
  • 16
  • 18
52
votes
5 answers

kotlin.NotImplementedError: An operation is not implemented: not implemented Error from ImageButton Click

Getting this Error kotlin.NotImplementedError: An operation is not implemented: not implemented I am implementing an ImageButton click listener Requirement :- I want to perform an action on imagebutton click , but getting the above mentioned…
51
votes
8 answers

Android - save/restore fragment state

I have an Activity in which I go through several fragments. In every fragment I have several views (EditText, ListView, Map, etc). How can I save the instance of the fragment that is shown at that moment? I need it to work when the activity is…
Stanete
  • 691
  • 1
  • 7
  • 13
50
votes
6 answers

Android Fragment does not respect match_parent as height

Sorry for the huge code dump, but I'm truly lost. MyActivity.java onCreate: super.onCreate(savedInstanceState); setContentView(R.layout.activity_singlepane_empty); mFragment = new PlacesFragment(); getSupportFragmentManager().beginTransaction() …
50
votes
3 answers

what is the different between onCreate() and onCreateView() lifecycle methods in Fragment?

I don't know when to use onCreate() or onCreateView(). I have used onCreate() and onCreateView() lifecycle methods. I think onCreate() for Activity and onCreateView() for Fragment. But I am not sure. Can I use onCreate() LifeCycle method in…
Cabezas
  • 9,329
  • 7
  • 67
  • 69
49
votes
8 answers

Event when the FragmentTransaction is completed

Is it possible to have an event when the FragmentTransaction is completed ? FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, fragment).commit(); In fact, I use a Drawer for my application and I…
lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
48
votes
4 answers

How to set Unit Test to Fragment in Android

I want to unit test an Android Fragment class. Can I set up a test using AndroidTestCase or do I need to use ApplicationTestCase? Are there any useful examples of how these two TestCases can be used? The testing examples on the developer site are…
47
votes
6 answers

Set up toolbar as actionbar in fragment

I want to set up my toolbar as an actionbar, but since your toolbar is a layoutelement it has to be in your layout. Now my layout is in my fragment. I added the toolbar in my layout and I call it within my fragment: //Toolbar Toolbar toolbar =…
Laurenswuyts
  • 2,144
  • 4
  • 21
  • 39
45
votes
3 answers

Why is a FrameLayout used for fragments?

Wherever I look, FrameLayout seems to be used as the FragmentContainer. Why is FrameLayout always seen with Fragments?
maysi
  • 5,457
  • 12
  • 34
  • 62