Thank you for the reply. I had second thoughts about my post and
removed it, but you're right on top of things, as usual ;-) As you
said, the arguments Bundle is critical for the proper restoration of a
Fragment if it gets saved away. What I wondered about was the code on
the client side where
The code fragment below creates two instances of MyFragment, which is
probably not what you intended.
One is created by the new operator outside the constructor (someone
doing new MyFragment(myIndexValue)) and another instance inside the
constructor (f = new MyFragment). The latter one, with
I think Dave's code can be slightly changed to have the desired affect
and still maintain constructor semantics
public class MyFragment extends Fragment {
public MyFragment() {}
public MyFragment(int index) {
//MyFragment f = new MyFragment();
Bundle args = new Bundle();
Yes I really suggest following the model in the sample, with a static
function to create the fragment with its arguments. It is not any more
lines of code, and avoids making mistakes like forgetting to declare an
empty constructor.
On Mon, Feb 14, 2011 at 6:47 AM, Kostya Vasilyev
4 matches
Mail list logo