随笔 - 23  文章 - 0 评论 - 14 trackbacks - 0

直接奔主题~!

结构如图:

Send_EmailActivity.java代码:

public class Send_EmailActivity extends Activity {

	private EditText to_txt;
	private EditText subject_txt;
	private EditText content_txt;
	private Button submit_btn;
	private Button reset_btn;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findAll();
		bind();
	}

	public void findAll() {
		to_txt = (EditText) this.findViewById(R.id.to_txt);
		content_txt = (EditText) this.findViewById(R.id.content_txt);
		submit_btn = (Button) this.findViewById(R.id.submit_btn);
		reset_btn = (Button) this.findViewById(R.id.reset_btn);
		subject_txt = (EditText) this.findViewById(R.id.subject_txt);
	}

	public void bind() {
		submit_btn.setOnClickListener(mylistener);
		reset_btn.setOnClickListener(mylistener);
	}

	private View.OnClickListener mylistener = new OnClickListener() {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i = new Intent(Intent.ACTION_SEND);
			i.setType("text/plain"); // 模拟器请使用这行
			// i.setType("message/rfc822") ; // 真机上使用这行
			String receive = to_txt.getText().toString().trim();
			i.putExtra(Intent.EXTRA_EMAIL, new String[] { receive });
			i.putExtra(Intent.EXTRA_SUBJECT, subject_txt.getText().toString()
					.trim());
			i.putExtra(Intent.EXTRA_TEXT, content_txt.getText().toString()
					.trim());
			startActivity(Intent.createChooser(i, "send"));
			
		}

	};
}

main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<TextView android:text="收件人" android:id="@+id/textView1"
		android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
	<EditText android:layout_width="fill_parent" android:id="@+id/to_txt"
		android:layout_height="wrap_content">
		<requestFocus></requestFocus>
	</EditText>
	<TextView android:text="内容" android:id="@+id/textView2"
		android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
	<EditText android:layout_width="fill_parent" android:id="@+id/content_txt"
		android:layout_height="wrap_content"></EditText>
	<TextView android:text="主题" android:id="@+id/textView4"
		android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
	<EditText android:layout_width="fill_parent" android:id="@+id/subject_txt"
		android:layout_height="wrap_content"></EditText>
	
	<LinearLayout android:gravity="center"
		android:layout_width="fill_parent" android:id="@+id/linearLayout1"
		android:layout_height="wrap_content">
		<Button android:id="@+id/submit_btn" android:text="submit"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
		<Button android:id="@+id/reset_btn" android:text="reset"
			android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
	</LinearLayout>
</LinearLayout>

 

androidManifest.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="Send_Email.Jason"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Send_EmailActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>
posted on 2011-09-22 16:50 Jwc 阅读(...) 评论(...) 编辑 收藏