All Questions

96
votes
12answers
18587 views

NullPointerException accessing views in onCreate()

This is a canonical question for a problem frequently posted on StackOverflow. I'm following a tutorial. I've created a new activity using a wizard. I get NullPointerException when attempting to call...
540
votes
11answers
218097 views

Best practice for instantiating a new Android Fragment

I have seen two general practices to instantiate a new Fragment in an application: Fragment newFragment = new MyFragment(); and Fragment newFragment = MyFragment.newInstance(); The second option...
635
votes
31answers
268960 views

onActivityResult is not being called in Fragment

The activity hosting this fragment has its onActivityResult called when the camera activity returns. My fragment starts an activity for a result with the intent sent for the camera to take a picture....
211
votes
22answers
131546 views

Retrieve a Fragment from a ViewPager

I'm using a ViewPager together with a FragmentStatePagerAdapter to host three different fragments: [Fragment1] [Fragment2] [Fragment3] When I want to get Fragment1 from the ViewPager in the Fragme...
779
votes
30answers
422163 views

findViewById in Fragment

I am trying to create an ImageView in a Fragment which will refer to the ImageView element which I have created in the XML for the Fragment. However, the findViewById method only works if I extend an ...
335
votes
6answers
188789 views

Once for all, how to correctly save instance state of Fragments in back stack?

I have found many instances of a similar question on SO but no answer unfortunately meets my requirements. I have different layouts for portrait and landscape and I am using back stack, which both pr...
235
votes
17answers
154340 views

Replace Fragment inside a ViewPager

I'm trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I'm looking for to achieve is to replace a fragment, positioned on the first page of the ViewPager, with another one. ...
289
votes
20answers
95361 views

Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment

I have an application with three tabs. Each tab has its own layout .xml file. The main.xml has its own map fragment. It's the one that shows up when the application first launches. Everything works ...
132
votes
10answers
183363 views

Passing data between a fragment and its container activity

How can I pass data between a fragment and its container activity? Is there something similar to passing data between activities through intents? I read this, but it didn't help much: http://develope...
163
votes
6answers
213477 views

How to implement a ViewPager with different Fragments / Layouts

When I start an activity which implements viewpager, the viewpager created various fragments. I want to use different layouts for each fragment, but the problem is that viewpager shows only two layout...

Previous Next