1

有人可以帮我一个代码吗?我有一个联系表格,我希望您可以将表格连同联系表格的所有信息一起发送到 hotmail。如果您单击发送 (verzenden) 按钮,我想将表单发送到 serhildan_akdeniz@hotmail.com。

Java代码:

package com.MijnEersteApp;

import android.app.Activity;

import android.os.Bundle;

//import android.view.View;

import android.content.Intent;

//import android.widget.Button;

//import android.widget.AdapterView;

//import android.widget.AdapterView.OnItemSelectedListener;

//import android.widget.ArrayAdapter;

//import android.widget.Spinner;

//import android.widget.Toast;

import android.widget.EditText;


public class MijnEersteAppActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    

        final EditText naamField = (EditText) findViewById(R.id.editTextNaam);
        //String naam = naamField.getText().toString();
        if(naamField.getText().toString().length()==0)  
        {           
         naamField.setError( "Vul uw naam in" );  
        }  

        final EditText mailField = (EditText) findViewById(R.id.editTextMail);
        //String mail = mailField.getText().toString();
        if(mailField.getText().toString().length()==0)  
        {           
         mailField.setError( "Vul uw email in" ); 

         final EditText mobielField = (EditText) findViewById(R.id.editTextMobiel);
         //String mobiel = mobielField.getText().toString();
         if(mobielField.getText().toString().length() != 10)  
         {           
          mobielField.setError( "Vul een geldig telefoonnummer in" );
          if(mobielField.getText().toString().length()==0)
          {
              mailField.setError("Vul uw telefoonnummer in");


        final EditText berichtField = (EditText) findViewById(R.id.editTextBericht);
        //String bericht = berichtField.getText().toString();
        if(berichtField.getText().toString().length()==0)  
        {           
         berichtField.setError( "Vul uw bericht in" );  
        }

       // final Spinner onderwerpSpinner = (Spinner) findViewById(R.id.SpinnerOnderwerpType);  
        //String onderwerpType = onderwerpSpinner.getSelectedItem().toString();

        Intent email = new Intent(Intent.ACTION_SEND); 
        email.putExtra(Intent.EXTRA_EMAIL, new String[]{"serhildan_akdeniz@hotmail.com"});           
        email.putExtra(Intent.EXTRA_SUBJECT, "Klacht"); 
        email.putExtra(Intent.EXTRA_TEXT, berichtField.getText()); 
        email.setType("message/rfc822");
        startActivity(Intent.createChooser(email, "Serhildan")); 



        }
}
  }
  }
}

主要代码:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/contact" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/naam" />

    <EditText
        android:id="@+id/editTextNaam"
        android:layout_width="wrap_content"
        android:layout_height="26dp"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/mobiel" />



    <EditText
        android:id="@+id/editTextMobiel"
        android:layout_width="wrap_content"
        android:layout_height="26dp"
        android:ems="10"
        android:inputType="phone" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/mail" />

    <EditText
        android:id="@+id/editTextMail"
        android:layout_width="wrap_content"
        android:layout_height="26dp"
        android:ems="10"
        android:inputType="textEmailAddress" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/onderwerp" />


    <Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/onderwerp_array"
        android:prompt="@string/onderwerp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/bericht" />





    <EditText
        android:id="@+id/editTextBericht"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:ems="10"
        android:inputType="textMultiLine" />


    <Button
     android:id="@+id/buttonSend"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/verzenden"   
     />   

</LinearLayout>
4

1 回答 1

1
package com.MijnEersteApp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;  
import android.app.AlertDialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class MijnEersteAppActivity  extends Activity implements OnClickListener, OnItemSelectedListener{
/** Called when the activity is first created. */
    EditText naamField,mailField ,mobielField,berichtField;
    Spinner subject;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);    

    naamField = (EditText) findViewById(R.id.editTextNaam);
    mailField = (EditText) findViewById(R.id.editTextMail);
    mobielField = (EditText) findViewById(R.id.editTextMobiel);       
    berichtField = (EditText)findViewById(R.id.editTextBericht);

    subject=(Spinner)findViewById(R.id.spinner);
    String subjects[]=new String[]{"Default","Klacht","Vraag","Opmerking","Applicatie"};
    subject.setOnItemSelectedListener(this);
    ArrayAdapter<String> sa = new ArrayAdapter<String>(getApplicationContext(),
        android.R.layout.simple_spinner_item, subjects);
    sa.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    subject.setAdapter(sa);;        


    final Button buttonSend= (Button)findViewById(R.id.buttonSend);        
    buttonSend.setOnClickListener(this);
  }

public void onClick(View v) 
{
         if(naamField.getText().toString().length()==0)  
         {           
          naamField.setError( "Vul uw naam in" );  
         }  
         else if(mailField.getText().toString().length()==0)  
         {           
          mailField.setError( "Vul uw email in" ); 
         }
         else if(mobielField.getText().toString().length() != 10)  
         {           
           mobielField.setError( "Vul een geldig telefoonnummer in" );
         }
         else if(berichtField.getText().toString().length()==0)  
         {           
          berichtField.setError( "Vul uw bericht in" );  
         }
         else if(subject.getSelectedItemPosition()==0)  
         {           
          Toast.makeText(MijnEersteAppActivity.this,"Please select the Subject",Toast.LENGTH_SHORT).show(); 
         }
         else
         {  
            String body=
         "Name : "+naamField.getText().toString()+"<br>Mobile :"+mobielField.getText().toString()+
          "<br>Email :"+mailField.getText().toString()+"<br>Bericht :"+berichtField.getText().toString();  

            Intent email = new Intent(Intent.ACTION_SEND); 
            email.putExtra(Intent.EXTRA_EMAIL, new String[]{"serhildan_akdeniz@hotmail.com"});           
            email.putExtra(Intent.EXTRA_SUBJECT, subject.getSelectedItem().toString()); 
            email.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body)); 
            email.setType("message/rfc822");
            startActivityForResult(Intent.createChooser(email, "Serhildan"),1); 
         }         
  }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{

    new AlertDialog.Builder(MijnEersteAppActivity.this)
.setMessage("Your requested has been Accepted\nThank You")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) 
{
  dialog.cancel();
    }
})  
    .show();
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}
}
于 2012-07-16T11:49:26.687 回答