0

I'm trying to create a DialogFragment class that allows you to enter in four fields, and click a "done" button. Upon clicking the button, the DialogFragment should change certain text values and then terminate back to the main screen.

So far I have it doing everything I want it to do, except the terminating. The Dialog changes the selected TextView to "hello" and just lingers.

Can anyone show me how to get it to go away? Thanks!

public class TeamFragment extends DialogFragment {
    TextView team1, team2, score1, score2;

    public TeamFragment(View t1, View t2, View s1, View s2) {
        team1=(TextView) t1;
        team2=(TextView) t2;
        score1=(TextView) s1;
        score2=(TextView) s2;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.team_score_layout, container);
        //mEditText = (EditText) view.findViewById(R.id.txt_your_name);
        getDialog().setTitle("Enter Team Name");
        Button b = (Button) view.findViewById(R.id.teamButton);

        b.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
            team1.setText("hello");

          }
        });
        return view;
    }
}
Trinimon
  • 13,839
  • 9
  • 44
  • 60
Daniel Imberman
  • 618
  • 1
  • 5
  • 18
  • Why don't you use `public Dialog onCreateDialog()` instead of the `View onCreateView`? – TronicZomB Apr 23 '13 at 19:20
  • Are you trying to dismiss the dialog or are you trying to pop the back stack to a later screen? – TronicZomB Apr 23 '13 at 19:23
  • @TronicZomB The main reason I did the oncreateview was that I wanted to be able to access the xml file team_score_layout. Would creating a dialog allow me to use this xml file while being able to exit the dialog? Also, I'm trying to create a dialog window on top of a main screen, and once i am done with the dialog, be able to essentially pop the window and go back to the main screen. – Daniel Imberman Apr 23 '13 at 19:32
  • Yea you can still set the view via an xml with the `onCreateDialog`. Use `LayoutInflater inflater = getActivity().getLayoutInflater();` and then on your AlertDialog Builder you can use `builder.setView(inflater.inflate(R.layout.name_dialog, null));` and at the end `return builder.create();` and when you call this fragment just create a new instance of it like any other fragment and then just do myDialog.show(getFragmentManager(), "TAG");` – TronicZomB Apr 23 '13 at 19:36

1 Answers1

1

You can dismiss the DialogFragment using the following method

dismiss()
Benoit
  • 4,549
  • 3
  • 28
  • 45