title: Sending email from a fragment activity contact form
body: <p>I know questions like this have been asked already, but even after studying several other people's problems I still can't get my code to work, mostly because differences between projects have made it difficult for me to understand what and how to do.</p>
  
  <p>Usually this would work, but the form is in a fragment activity so naturally I've run against several problems (some I've solved, others not), that happen because fragments don't extend this or that etc.</p>
  
  <pre><code>package com.example;
  
  import android.app.Fragment;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class Fragment1 extends Fragment{
  
  @Override
  public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
      setHasOptionsMenu(true);
      View fragment1View=inflater.inflate(R.layout.fragment1,container,false);
      return fragment1View;
  
  }
  
  public void sendEmail(View button){
      final EditText formName=(EditText)findViewById(R.id.formName);
      String clientName=formName.getText().toString();
      final EditText formEmail=(EditText)findViewById(R.id.formEmail);
      String clientEmail=formEmail.getText().toString();
      final EditText formDetails=(EditText)findViewById(R.id.formDetails);
      String clientDetails=formDetails.getText().toString();
  
      Intent i = new Intent(Intent.ACTION_SEND);
      i.setType("message/rfc822");
      i.putExtra(Intent.EXTRA_EMAIL,new String[]{"example@email.com"});
      i.putExtra(Intent.EXTRA_SUBJECT, "New Private Service Request");
      i.putExtra(Intent.EXTRA_TEXT, "TODO: compose message body");
      try {
          startActivity(Intent.createChooser(i, "Send email with...?"));
      } catch (android.content.ActivityNotFoundException exception) {
          Toast.makeText(Fragment1.this.getActivity(), "No email clients installed on device!", Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Basically what happens is that the findViewById for the EditText controls are all underlined as errors: "The method findViewById(int) is undefined for the type Fragment1".
  I have tried this:</p>
  
  <pre><code>final EditText formName=(EditText)fragment1View.findViewById(R.id.formName);
  </code></pre>
  
  <p>And though this supposedly helped some people, for me the fragment1View is simply unresolved, even though I have declared it in the onCreateView.</p>
  
  <p>I've tried alot of things and just don't know what to do. I wanted to give up and go with a standard Activity instead of Fragment, but it has to be fragment. Please help :/</p>