java - 单击按钮无响应

标签 java android email

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

电子邮件.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();
    }    
}

最佳答案

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

关于java - 单击按钮无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12246324/

相关文章:

ios - MFMailComposeViewController 自定义

android - 在现有 SQLITE 中创建附加表(无数据丢失)

java - 是否可以在 javax.mail.MimeMessage 中隐藏电子邮件地址?

java - BufferedWriter 停止写入

java - 为什么这个十六进制值得到不同的十进制值?

android - 无法在离线模式下构建。 "No cached version listing for androidx.fragment:fragment:[1.2.0] available for offline mode"

java - 使用 touchDragged 方法后,如何找到 libgdx 中 actor 的新位置?

php - Codeigniter 注册时自动发送欢迎电子邮件 - 帮助

java - Jackson - 反序列化 ManyToOne 关系时出现惰性列表初始化错误

java - 自定义颜色不可用