尝试将EditText表单提交到我的电子邮件时出错?没有应用可以执行此操作?

时间:2017-01-02 20:23:46

标签: java android email android-studio onclicklistener

这是错误讯息......

  

" Class'从OnClickListener派生的匿名类'必须是   声明抽象或实现抽象方法' onClick(查看)'在   ' OnClickListener'"

这是源代码,任何人都知道如何解决这个错误?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_donate);

    Button donationButton = (Button) findViewById(R.id.donation_submit_button);
    donationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(DonateActivity.this, PostDonationActivity.class));
        }
    });


    donationButton.setOnClickListener(new View.OnClickListener() {
        public void onClick() {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL, new String[]{
                    "ethan.reinsch@fillmorecentral.org"
            });
            i.putExtra(Intent.EXTRA_SUBJECT, "Test Subject");
            i.putExtra(Intent.EXTRA_TEXT, "Test Body");
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(DonateActivity.this, "There are no email clients installed.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    });

非常感谢所有帮助!!我是Android Studio和Android App Development的新手。谢谢!

UPDATE /编辑: 我得到它的工作,但当我点击提交,它说没有应用程序可以执行此操作?我正在使用模拟器。在实际设备上会有所不同吗?谢谢!

2 个答案:

答案 0 :(得分:1)

donationButton.setOnClickListener(new View.OnClickListener() {
       // here is problem
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL, new String[]{
                    "ethan.reinsch@fillmorecentral.org"
            });
            i.putExtra(Intent.EXTRA_SUBJECT, "Test Subject");
            i.putExtra(Intent.EXTRA_TEXT, "Test Body");
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(DonateActivity.this, "There are no email clients installed.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    });

答案 1 :(得分:0)

类似这样,请注意SENDTO

   Intent i = new Intent(Intent.ACTION_SENDTO);
    i.setData(Uri.parse("mailto: " + EMAIL.getText().toString()));
    i.putExtra(Intent.EXTRA_SUBJECT, editText.getText().toString());
   try {
    startActivity(Intent.createChooser(i, ""));