0

我正在尝试为电子邮件活动设置一个按钮,但是使用当前代码我没有收到任何错误,但是当我单击该按钮时没有响应

电子邮件.java

public class Email extends Activity implements View.OnClickListener {

    EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
            outro;
    String emailAdd, beginning, name, stupidAction, hatefulAct, out;
    Button sendEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.email);
        initializeVars();
        sendEmail.setOnClickListener(this);
    }

    private void initializeVars() {
        // TODO Auto-generated method stub
        personsEmail = (EditText) findViewById(R.id.etEmails);
        intro = (EditText) findViewById(R.id.etIntro);
        personsName = (EditText) findViewById(R.id.etName);
        stupidThings = (EditText) findViewById(R.id.etThings);
        hatefulAction = (EditText) findViewById(R.id.etAction);
        outro = (EditText) findViewById(R.id.etOutro);
        sendEmail = (Button) findViewById(R.id.bSentEmail);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

        convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
        String emailaddress[] = { emailAdd };
        String message = "Well hello "
                + name
                + " I just wanted to say "
                + beginning
                + ".  Not only that but I hate when you "
                + stupidAction
                + ", that just really makes me crazy.  I just want to make you "
                + hatefulAct
                + ".  Welp, thats all I wanted to chit-chatter about, oh and"
                + out
                + "Oh and you could visit facebook www.facebook.com/"
                + '\n' + "PS. I think I love you...    ";

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"I hate you");
        emailIntent.setType("Plain/Text");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
        startActivity(emailIntent);

    }


    private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
        // TODO Auto-generated method stub
        emailAdd = personsEmail.getText().toString();
        beginning = intro.getText().toString();
        name = personsName.getText().toString();
        stupidAction = stupidThings.getText().toString();
        hatefulAct = hatefulAction.getText().toString();
        out = outro.getText().toString();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }    
}

菜单.java

public class Menu extends Activity {

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

        //Setting Up Button

        Button but1 =(Button) findViewById(R.id.bEmail);

         but1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                startActivity(new Intent("com.guess.guessme.EMAIL"));
            }
        });

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }    
}
4

5 回答 5

1

您可以使用此代码。它可以解决您的问题: startActivity(new Intent(Menu.this, Email .class));

于 2012-09-03T11:05:01.000 回答
0

尝试更改您的 fromemailIntent.setType("Plain/Text");emailIntent.setType("text/html"); 进行以下更改可能会对您有所帮助

startActivity(Intent.createChooser(emailIntent, "Send mail..."));
于 2012-09-03T10:58:39.923 回答
0

尝试这个:

startActivity(new Intent("com.guess.guessme.Email"));

并确保您的清单文件中也说明了电子邮件活动。

于 2012-09-03T10:58:53.933 回答
0

试试看

 emailIntent.setType("message/rfc822");
 Email.this.startActivity(Intent.createChooser(email, "Choose an Email client :");
于 2012-09-03T11:03:58.997 回答
0

尝试这样做 -

看来您正在实施错误的侦听器。尝试导入OnClickListener而不是View.OnClickListener像下面这样 -

public class Email extends Activity implements OnClickListener

用下面的代码。

public void onClick(View v) {
    // TODO Auto-generated method stub

switch(v.getId())
{

case R.id.bSentEmail:

    convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
    String emailaddress[] = { emailAdd };
    String message = "Well hello "
            + name
            + " I just wanted to say "
            + beginning
            + ".  Not only that but I hate when you "
            + stupidAction
            + ", that just really makes me crazy.  I just want to make you "
            + hatefulAct
            + ".  Welp, thats all I wanted to chit-chatter about, oh and"
            + out
            + "Oh and you could visit facebook www.facebook.com/"
            + '\n' + "PS. I think I love you...    ";

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"I hate you");
    emailIntent.setType("Plain/Text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
    startActivity(emailIntent);

break;
}

}
于 2012-09-03T11:04:43.693 回答