title: Return data from DialogFragment to MainActivity
body: <p>I'm trying return a String from the DialogFragment, following this instructions <a href="https://stackoverflow.com/a/14808425/2933117">https://stackoverflow.com/a/14808425/2933117</a> , but I only get logcat error</p>
  
  <p><code>java.lang.ClassCastException: com.example.testinterface.MainActivity cannot be cast to com.example.testinterface.InterDialog$EditNameDialogListener</code></p>
  
  <p>I appreciate any help or explanation of why I get an error, thanks in advance.</p>
  
  <p>Here is my code:</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
      private Button Btn;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Btn=(Button)findViewById(R.id.button1);
  
          Btn.setOnClickListener(new View.OnClickListener(){
              public void onClick (View view) {
                  FragmentManager fm = getSupportFragmentManager();
                  InterDialog pruebafragment = new InterDialog();
                  pruebafragment.show(fm,"MyFragment");
              }
          });
  
      }
  
      public void onFinishEditDialog (String inputText) {
          Toast.makeText(this, "Hi, " + inputText, Toast.LENGTH_SHORT).show();
      }
  
  }
  </code></pre>
  
  <p>and <strong>DialogFragment</strong> </p>
  
  <pre><code>public class InterDialog extends DialogFragment {
  
      public interface EditNameDialogListener {
          void onFinishEditDialog(String inputText);
      }
  
      public InterDialog() {
          // Empty constructor required for DialogFragment
      }
  
      EditNameDialogListener activity;
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
       View view = inflater.inflate(R.layout.new_layout, container);  
  
       activity = (EditNameDialogListener) getActivity(); 
  
       Button button = (Button)view.findViewById(R.id.Btnreturn);
       button.setOnClickListener(new OnClickListener() {
           public void onClick(View v) {
               activity.onFinishEditDialog("errorrrr");
               getDialog().dismiss();
           }
       });
  
       return view;
  
    }
  }
  </code></pre>