Question

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;
    }
}
Was it helpful?

Solution

You can dismiss the DialogFragment using the following method

dismiss()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top