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
31
votes
5 answers

Fragment lost transition animation after configuration change

I'm inserting Fragments into the Activity using this code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); FragmentManager fm = getFragmentManager(); String tag =…
Max
  • 311
  • 3
  • 5
31
votes
10 answers

how to go back to previous fragment on pressing manually back button of individual fragment?

I have only one activity and multiple fragments in my application. Two main fragment A(left) and B(right). Fragment A1 called from A B1 called from B B2 called from B1 All fragments have individual back buttons. So when I press back button of…
Mihir Shah
  • 1,799
  • 3
  • 29
  • 49
30
votes
4 answers

Android: Can you nest Fragments?

Is it possible to stick a Fragment in the layout of another Fragment? Has anyone tried this?
Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
30
votes
8 answers

How can I call OnActivityResult inside Fragment and how it work?

I want to know is it possible on onActivityResult()to use inside Fragment and if yes then how it works please explain with example.
Shweta Nandha
  • 728
  • 1
  • 8
  • 19
30
votes
6 answers

Bad window token, you cannot show a dialog before an Activity is created or after it's hidden

I am using an AppIntro library in my app. It has 3 slides. I want to ask the user something when the third slide is shown. To achieve that I am using material dialogs by afollestad. My code in the AppIntro Activity looks like that: @Override …
jublikon
  • 3,427
  • 10
  • 44
  • 82
30
votes
2 answers

how to get the onWindowFocusChanged on Fragment?

I am using Android Sliding Menu using Navigation Drawer. I know that onWindowFocusChanged work on MainActivity. How can I check is it hasFocus on Fragment? someone said that I can pass the hasFocus to fragment, but I dont know how to do this. Can…
Ben Luk
  • 735
  • 2
  • 8
  • 15
30
votes
2 answers

difference between fragmentTransaction.add and fragmentTransaction.replace

What I already known is: after fragmentTransaction.replace(), current fragment's onStop() function will be called while fragmentTransaction.add() won't. and after calling fragMgr.popBackStack();, we will return to previous fragment no matter…
Wood
  • 945
  • 1
  • 9
  • 18
30
votes
1 answer

Access Fragment View from Activity's onCreate

I am in the process of making my first app for Android, and I have a Fragment that gets added to my Activity in the Activity's onCreate() method. The problem I am facing is that I am unable to find any of the views contained within the Fragment from…
Dan
  • 1,198
  • 4
  • 17
  • 34
29
votes
4 answers

contextthemewrapper cannot be cast to activity

in my small app i have a PageAdapter->Fragment->ListView->ImageView. On onImageClick i want display my image in another Fragment (Fragment3), but when i load an image in my Fragment3 get an Exception public class Fragment3 extends DialogFragment…
zond
  • 1,473
  • 1
  • 21
  • 34
29
votes
4 answers

ViewPager update fragment on swipe

i have a problem that i have been struggling with for the past 2 days. I am building an app that uses ActionBar, ViewPager & FragmentPagerAdapter. The code for the Activity, Fragments & FragmentPagerAdapter are exactly as the ones stated in the…
Steve
  • 293
  • 1
  • 3
  • 5
29
votes
7 answers

findViewById returns NULL when using Fragment

I'm new to Android developing and of course on Fragments. I want to access the controls of my fragment in main activity but 'findViewById' returns null. without fragment the code works fine. Here's part of my code: The fragment:
mammadalius
  • 3,263
  • 6
  • 39
  • 47
28
votes
10 answers

Unable to override onCreateOptionsMenu in ListFragment

I created an app that supports both phone and tablet version so i use the android-support-v4.jar library. My activity extends the ListFragment and I tried to override the onCreateOptionsMenu(Menu menu, MenuInflater inflater), as in the following…
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
28
votes
5 answers

Fragment lifecycle with respect to it's activity

Situation My activity waits on an Async operation and after it hears back from async operation, it needs to pass information to 2 fragments inside it. Requirement 1. Both fragments need their onCreateView calls to be done for them to have their…
Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
28
votes
1 answer

Programmatically adding fragment to framelayout in android

I am trying to build a UI combining both static and dynamic elements. For this, I have divided my activity into fragments - all app navigation is then done by replacing fragments instead of navigating between activities. In my main activity layout,…
Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
28
votes
7 answers

FragmentStatePagerAdapter IllegalStateException: is not currently in the FragmentManager

I'm getting this on some cases, in onResume(), of an activity which uses a FragmentStatePagerAdapter. When using device's back button. Not always. Not reproducible. I'm using support package v4, last revision (8). Already searched with google, no…
User
  • 31,811
  • 40
  • 131
  • 232