添加从编辑文本字段中的文本到电子邮件 [英] Adding text from edit text field into an email

查看:131
本文介绍了添加从编辑文本字段中的文本到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,并希望有一个接触我们在用户输入自己的姓名,地址,电话号码,和一个注释部分。然后,他们会点击撰写邮件按钮,它会加载文本的电子邮件程序自动。有一些的code制定了,但不知道如何从编辑文本的文本到我的邮箱味精。任何人对我怎么能做到这一点的任何建议。我从XML文件和我的java文件附上code。

I have an app and want to have a contact us for where the user inputs their name, address, phone number, and a comment section. Then they will click on compose mail button and it will load the text into the email automaticlly. have some of the code worked out but not sure how to get the text from the edit text into my email msg. anyone have any suggestions on how i can do this. I have attached the code from my xml file and my java file.

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;

 public class Contactform extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactform);

    Button email = (Button) findViewById(R.id.button30);
    email.setOnClickListener(new View.OnClickListener()  {

        @Override
        public void onClick(View v){
            //TODO Auto-generated method stub
            Intent email = new Intent(android.content.Intent.ACTION_SEND);

            /* Fill it with Data */
            email.setType("plain/text");
            email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ladsoffice@lads-to-leaders.org"});
            email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
            email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");

            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(email, "Send mail..."));
        }
    });
}


 }

和这里的xml文件

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#bf311a" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:text="@string/name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_marginLeft="37dp"
        android:layout_toRightOf="@+id/textView1"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="35dp"
        android:text="@string/addy"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentRight="true"
        android:inputType="textPostalAddress" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="30dp"
        android:textColor="#000000"
        android:text="@string/cell"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/editText2"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:textColor="#000000"
        android:text="@string/questions"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="25dp"
        android:inputType="textMultiLine" />

    <Button
        android:id="@+id/button30"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText4"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="47dp"
        android:background="@drawable/composemail" />

</RelativeLayout>

和这里是我的什么形式的样子,是否可以帮助一个SS

and here is a ss of what my form looks like if that helps

感谢您的帮助,你可以给。还在学习了一下如何做一些这方面的东西,所以我道歉,如果这已经被问过,但一直在寻找了两天,似乎无法找到我需要做到这一点。

Thank you for any help you can give. Still learning a bit on how to do some of this stuff so i apologize if this has been asked before but been searching for two days and can't seem to find what i need to do this.

好了,谁想要知道这里是修正code。修改需要的唯一codeI是code为Java文件,因此多数民众赞成在只有codeI将发布。

Ok for those who want to know here is the corrected code. The only code i needed to modify was the code for the Java file so thats the only code i will post.

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;

 public class Contactform extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactform);

    final EditText name = (EditText) findViewById(R.id.editText1);
    final EditText addy = (EditText) findViewById(R.id.editText2);
    final EditText cell = (EditText) findViewById(R.id.editText3);
    final EditText questions = (EditText) findViewById(R.id.editText4);

    Button email = (Button) findViewById(R.id.button30);
    email.setOnClickListener(new View.OnClickListener()  {

        @Override
        public void onClick(View v){
            //TODO Auto-generated method stub
            Intent email = new Intent(android.content.Intent.ACTION_SEND);

            /* Fill it with Data */
            email.setType("plain/text");
            email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ladsoffice@lads-to-leaders.org"});
            email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
            email.putExtra(android.content.Intent.EXTRA_TEXT, 
                    "name:"+name.getText().toString()+'\n'+"address:"+addy.getText().toString()+'\n'+"phone:"+cell.getText().toString()+'\n'+'\n'+questions.getText().toString()+'\n'+'\n'+"Sent from the Lads to Leaders/Leaderettes Android App.");

            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(email, "Send mail..."));
        }
    });
}


 }

好了,所以只是一个快速explaintion。你有你的onCreate方法后宣布在code您编辑文本。它必须说,最后在它面前也是如此。然后你输入你的字符串到意向多余的文字。此外,我添加了单引号'\ N'。所以我做了这个动作将作为输入按钮给每个项目单独的行例如,我只想名在同一行名称+了mystring +'\ N'。这将使你的名字和字符串出现在同一行,然后再下移一行下一行。希望这是因为,它可以帮助别人了。

Ok so just a quick explaintion. you have to declare your edit text in the code after your oncreate method. It must say final in front of it as well. Then you input your strings into the intent for EXTRA TEXT. also i added the '\n' in single quotes. this action will act as an enter button giving each item its own line so for example i only wanted name on one line so i did name+mystring+'\n'. this will make your name and string appear on one line and then go down one line for the next line. Hope this makes since and it helps someone else out.

推荐答案

您可以把里面的中的所有数据email.putExtra(android.content.Intent.EXTRA_TEXT,从小伙子发送到领导者/ Leaderettes Android应用程序);

You can put all data inside email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");

首先获取所有的EditText通过ID在这里的OnCreate像

First Get all EditText by ID here in oncreate Like

 EditText name = (EditText) findViewById(R.id.editext1);
 EditText address = (EditText) findViewById(R.id.editext2);
 EditText phone = (EditText) findViewById(R.id.editext3);

然后把所有的数据

Then put all data

email.putExtra(android.content.Intent.EXTRA_TEXT, 
"name:"+name.getText().toString()+"address:"+address.getText().toString()+"phone:
 "+phone.getText().toString());

享受:)

这篇关于添加从编辑文本字段中的文本到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆