gpt4 book ai didi

java - 将 Spinners 的文本发送到邮件

转载 作者:行者123 更新时间:2023-11-29 19:42:37 26 4
gpt4 key购买 nike

我刚开始在 android studio 中学习编码.....我有这个小问题想解决!我想从 spinners 和 editText 获取文本并将其放入邮件正文!我已经学会了如何获取 editText 的文本并在邮件中获取它。我也只想添加微调器的文本,但我真的不知道该怎么做。这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.virtusplus.sofronis_systems.Contactform">


<Spinner
android:id="@+id/static_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:backgroundTint="#dce1e3"
android:background="#dce1e3"
android:clickable="false"
android:textAlignment="gravity"
android:popupBackground="#dce1e3" />

<Spinner
android:id="@+id/dynamic_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#dce1e3"
android:popupBackground="#dce1e3"
android:textAlignment="gravity"
android:visibility="visible"
android:layout_below="@+id/textView7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Επιλέξτε προϊόν:"
android:id="@+id/textView6"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Ποσότητα:"
android:id="@+id/textView7"
android:layout_below="@+id/static_spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Ονοματεπώνυμο:"
android:id="@+id/textView8"
android:layout_below="@+id/dynamic_spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/subject"
android:layout_below="@+id/textView8"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Σχόλια:"
android:id="@+id/textView10"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/subject" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/body"
android:layout_below="@+id/textView10"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEND"
android:id="@+id/sendEmail"
android:background="#0e89cc"
android:textColor="#ffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />

</RelativeLayout>

这是我的 javaclass:

package com.virtusplus.sofronis_systems;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Contactform extends AppCompatActivity {


private EditText subject;
private EditText body;

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

Spinner staticSpinner = (Spinner) findViewById(R.id.static_spinner);

// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapter = ArrayAdapter
.createFromResource(this, R.array.brew_array,
android.R.layout.simple_spinner_item);

// Specify the layout to use when the list of choices appears
staticAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// Apply the adapter to the spinner
staticSpinner.setAdapter(staticAdapter);

Spinner dynamicSpinner = (Spinner) findViewById(R.id.dynamic_spinner);

String[] items = new String[]{"1", "2", "3", "4", "5"};

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items);

dynamicSpinner.setAdapter(adapter);

dynamicSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Log.v("item", (String) parent.getItemAtPosition(position));
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
subject = (EditText) findViewById(R.id.subject);
body = (EditText) findViewById(R.id.body);

Button sendBtn = (Button) findViewById(R.id.sendEmail);
sendBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendEmail();
// after sending the email, clear the fields
subject.setText("");
body.setText("");
}
});
String message = staticSpinner.getSelectedItem() +"and"+ dynamicSpinner.getSelectedItem() + body.getText().toString();

}

protected void sendEmail() {


Intent email = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
// prompts email clients only
email.setType("message/rfc822");
String[] to={"example@mail.com"};
email.putExtra(Intent.EXTRA_EMAIL, to);
email.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, body.getText().toString());

try {
// the user can choose the email client
startActivity(Intent.createChooser(email, "Choose an email client"));

} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Contactform.this, "No email client installed.",
Toast.LENGTH_LONG).show();
}
}
}

提前致谢!

最佳答案

尝试这可能是因为您错过了对 String() 的调用

String message = staticSpinner.getSelectedItem().toString() +"and"+ dynamicSpinner.getSelectedItem().toString() + body.getText().toString();

关于java - 将 Spinners 的文本发送到邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38380264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com