【发布时间】:2018-06-16 01:28:41
【问题描述】:
我想将 textview 的内容传递到消息正文中 该按钮适用于打开和发送邮件, 但是如何在消息正文中添加文本视图?
enter code public class Buy1Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
ImageUpload imgUploadObj = getIntent().getExtras().getParcelable("selected_image_upload");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_buy1);
TextView txa = (TextView) findViewById(tx);
txa.setText( " Name : " +
imgUploadObj.getName() + "\n" + " Brand : " + imgUploadObj.getBrand() +
"\n" + " Model : " + imgUploadObj.getModel() + "\n" + " Year : " +
imgUploadObj.getYear() + "\n" + " price : " + imgUploadObj.getPrice() +
"\n" + " desc + : " + imgUploadObj.getDesc());
Button startBtn = (Button) findViewById(R.id.sendEmail1);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendEmail();
}
});
}
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {"201416134@omancollege.edu.om"};
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, "whant to buy item");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i(" Mail sent...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Buy1Activity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
}这里
我的 xml
enter code <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tx"
android:layout_width="match_parent"
android:layout_height="250dp"
android:textStyle="bold"
android:text="TextView" />
<Button
android:id="@+id/sendEmail1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/compose_email"/>
这里 这是我完整的 java 和 xml 代码,没有编辑任何东西,也许我这样做会导致任何错误,因为我是初学者
【问题讨论】:
-
你要传递这个文本-TextView txa。进入您的邮件正文
-
是的,此文本的内容已经从 listview 传递,然后我希望 textview 的内容在我的消息正文中
-
mohamed 检查我的以下答案,
-
并且您错误地使用了 textview 参考,请使用下面的代码回答 TextView txa = (TextView) findViewById(R.id.tx);代替您的旧代码 TextView txa = (TextView) findViewById(tx);
-
嗨 Mohanmed,请分享您的错误和代码
标签: android email android-intent textview