2

I have an android application with a main activity extending a listactivity.

public class Main_activity extends ListActivity {...}

Out of the options menu, I want to send a part of the items via mail. To select the items, I want to display a dialogfragment.

Everything works fine, but I have to start a new intent (loosing my listview), this extending FragmentActivity, as it is not possible to use getSupportFragmentManager out of the ListActivity.

startActivity (new Intent (this, Fragment_Activity.class));

and

public class Fragment_Activity extends FragmentActivity implements EditNameDialogListener {...}

Is there any possibility to display the DialogFragment directly from my Main_activity? What do I have to change?

Berolino
  • 21
  • 1

1 Answers1

0

I would suggest that you change Main_activity to extend FragmentActivity and move your list code to a ListFragment. With your main activity extending FragmentActivity it gives you the chance to show the dialog fragment without losing the ListView and the underlying data.

UPDATE: Since you don't want to change your current design I see two ways forward:

1 Move the list data out of the ListActivity and into a data model of some kind so that you don't lose it. Create a static class to hold the list data or store it in SharedPreferences.

2 Use a custom dialog instead of a DialogFragment

Community
  • 1
  • 1
britzl
  • 9,742
  • 7
  • 38
  • 36
  • I haven't done anything with fragments until now. After reading a while, it doesn't sound easy. I think, I'll have to stay with my current code, until I have time to understand the fragments. Thanks for your answer... – Berolino May 23 '13 at 09:02
  • It really isn't that complex, but if you don't wanna do it right now I guess you will have to move the list data out of the ListActivity and into a data model of some kind so that you don't lose it. Create a static class to hold the list data or store it in SharedPreferences – britzl May 29 '13 at 11:01