【问题标题】:sendEmail method in dynamically created button?动态创建的按钮中的 sendEmail 方法?
【发布时间】:2018-01-22 15:06:41
【问题描述】:

我动态创建了按钮,我想通过单击这些按钮来发送电子邮件,但出现了问题。什么都没发生。 :(请帮助我,我是初学者。

AdapterListingOrders:

public class AdapterListingOrders extends AppCompatActivity {

private Button btnAccRejOrders;

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    btnAccRejOrders = (Button) findViewById(R.id.order_acc_rej);

    btnAccRejOrders.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("Send email", "");
            String[] TO = {""};
            String[] CC = {""};
            Intent emailIntent = new Intent(Intent.ACTION_SEND);

            emailIntent.setData(Uri.parse("mailto:"));
            emailIntent.setType("text/plain");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
            emailIntent.putExtra(Intent.EXTRA_CC, CC);
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
        }
    });
}
}

但是 onClick 不起作用。当我按下 btnAccRejOrders 时,LogCat 显示:

ViewPostImeInputStage processPointer 0
ViewPostImeInputStage processPointer 1

【问题讨论】:

  • 你在模拟器或真实设备中尝试
  • 如果你动态地创建了按钮,那么你如何从 xml 中通过它的视图 id 找到它? ?
  • @Naveen 在真实设备、三星 J7、logcat 中显示相同的 ViewPostImeInoutStage 进程指针 0 和 1。
  • @AalapPatel 我在adapter_listing_order.xml 中创建了按钮,然后在活动中我有私有类ListingOrdersAdapter 扩展了BaseAdapter,因此创建的按钮与我在Firebase 中的数据一样多。我遵循了本教程:coderzpassion.com/…

标签: android email button android-intent dynamic


【解决方案1】:
btnAccRejOrders.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("Send email", "");
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
            i.putExtra(Intent.EXTRA_TEXT   , "body of email");
            try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                }
        }
    });

【讨论】:

  • 同样的问题仍然存在:(
猜你喜欢
  • 1970-01-01
  • 2013-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
  • 2012-01-21
  • 2023-01-30
相关资源
最近更新 更多