All Questions

282
votes
31answers
275370 views

How to implement onBackPressed() in Fragments?

Is there a way in which we can implement onBackPressed() in Android Fragment similar to the way in which we implement in Android Activity? As the Fragment lifecycle do not have onBackPressed(). Is th...
570
votes
22answers
215122 views

How to determine when Fragment becomes visible in ViewPager

Problem: Fragment onResume() in ViewPager is fired before the fragment becomes actually visible. For example, I have 2 fragments with ViewPager and FragmentPagerAdapter. The second fragment is only a...
64
votes
11answers
134858 views

How to pass values between Fragments

I am pretty new to using Fragments. I am just trying to build a simple sample application that uses Fragments. My scenario is, I have two activities with one fragment inside each activity. The first ...
441
votes
10answers
200586 views

ViewPager and fragments — what's the right way to store fragment's state?

Fragments seem to be very nice for separation of UI logic into some modules. But along with ViewPager its lifecycle is still misty to me. So Guru thoughts are badly needed! Edit See dumb solution b...
254
votes
18answers
216319 views

Update ViewPager dynamically?

I can't update the content in ViewPager. A question: What is the relationship and correct usage of methods instantiateItem() and getItem() in FragmentPagerAdapter class? I was using only getItem() t...
370
votes
17answers
208378 views

How to handle button clicks using the XML onClick within Fragments

Pre-Honeycomb (Android 3), each Activity was registered to handle button clicks via the onClick tag in a Layout's XML: android:onClick="myClickMethod" Within that method you can use view.getId...
264
votes
4answers
128485 views

Understanding Fragment's setRetainInstance(boolean)

Starting with the documentation: public void setRetainInstance (boolean retain) Control whether a fragment instance is retained across Activity re-creation (such as from a configuration chang...
97
votes
11answers
189281 views

How to put Google Maps V2 on a Fragment Using ViewPager

I am trying to do a tab layout same in Play Store. I got to display the tab layout using a fragments and viewpager from androidhive. However, I can't implement google maps v2 on it. I searched the int...
136
votes
9answers
67039 views

Update data in ListFragment as part of ViewPager

I'm using the v4 compatibility ViewPager in Android. My FragmentActivity has a bunch of data which is to be displayed in different ways on different pages in my ViewPager. So far I just have 3 insta...
217
votes
4answers
83693 views

Do fragments really need an empty constructor?

I have a fragment with a Constructor with multiple arguments, everything worked fine during testphase but now after about 300 users downloaded the app, i have ONE occurence of that exception: androi...

Previous Next