Java 提交按钮不通过电子邮件发送从activity_main.xml收集的数据
我正在尝试使用editText从activity_main.xml收集数据输入,并在单击提交按钮时通过电子邮件将数据输入MainActivity.java。由于某些原因,单击“提交”按钮时不会执行任何操作。感谢您的帮助。非常感谢。以下是我的代码: 这是我的activity_main.xml代码:Java 提交按钮不通过电子邮件发送从activity_main.xml收集的数据,java,android,Java,Android,我正在尝试使用editText从activity_main.xml收集数据输入,并在单击提交按钮时通过电子邮件将数据输入MainActivity.java。由于某些原因,单击“提交”按钮时不会执行任何操作。感谢您的帮助。非常感谢。以下是我的代码: 这是我的activity_main.xml代码: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:background="@android:color/background_light">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/questions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.android.stool.MainActivity">
<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="@dimen/height"
android:layout_gravity="center_horizontal"
android:background="#303f9f"
android:contentDescription="@string/description"
android:paddingBottom="@dimen/padding"
android:paddingTop="@dimen/padding"
android:src="@drawable/logoconf" />
<EditText
android:id="@+id/presentationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:hint="@string/presentation"
android:inputType="text" />
<EditText
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:hint="@string/date"
android:inputType="date" />
<TextView
android:id="@+id/speaker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginStart="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:text="@string/speaker" />
<RatingBar
android:id="@+id/rating_bar1"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:isIndicator="false"
android:numStars="5"
android:rating="0"
android:stepSize="1"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/rating_bar1_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
/>
<TextView
android:id="@+id/visuals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:text="@string/visuals" />
<RatingBar
android:id="@+id/rating_bar2"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:isIndicator="false"
android:numStars="5"
android:rating="0"
android:stepSize="1"
tools:ignore="RtlHardcoded" />
<TextView
android:id="@+id/rating_bar2_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
/>
<TextView
android:id="@+id/useful"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:text="@string/useful" />
<RatingBar
android:id="@+id/rating_bar3"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginStart="@dimen/margin"
android:isIndicator="false"
android:numStars="5"
android:rating="0"
android:stepSize="1" />
<TextView
android:id="@+id/rating_bar3_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
/>
<TextView
android:id="@+id/recommend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:text="@string/recommend" />
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginStart="@dimen/margin"
android:orientation="horizontal">
<RadioButton
android:id="@+id/yes_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/y"
android:textAppearance="?android:textAppearanceMedium" />
<RadioButton
android:id="@+id/no_radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/n"
android:textAppearance="?android:textAppearanceMedium" />
</RadioGroup>
<EditText
android:id="@+id/suggestions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_marginTop="@dimen/margin"
android:hint="@string/suggestions"
android:inputType="textMultiLine" />
</LinearLayout>
<TextView
android:id="@+id/review_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Summary"
android:textSize="16sp"
android:textColor="@android:color/black"
android:layout_marginLeft="8dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
/>
<Button
android:id="@+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/questions"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/button_margin"
android:onClick="submit"
android:text="@string/submit" />
</RelativeLayout>
</ScrollView>
我的错误代码如下:
对于以下代码,=符号前的所有名称均为红色。所以,coolLogo是红色的,nameField是红色的,recDay是红色的,comCat是红色的,graPhics是红色的,advAnt是红色的,menDar是红色的,sugGest是红色的
coolLogo = (ImageView) findViewById(R.id.logo);
nameField = (EditText) findViewById(R.id.presentationName);
recDay = (EditText) findViewById(R.id.date);
comCat = (TextView) findViewById(R.id.speaker);
graPhics = (TextView) findViewById(R.id.visuals);
advAnt = (TextView) findViewById(R.id.useful);
menDar = (TextView) findViewById(R.id.recommend);
sugGest = (EditText) findViewById(R.id.suggestions);
对于下面的代码,setOnClickListener是红色的,v是红色的,name是红色的,priceMessage是红色的,并且)在;它是红色的
submitButton.setOnClickListener(new View.OnClickListener()
{
public void onClick (View v){
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto: example@gmail.com")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, "Presentation Review for: " + name);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
displayMessage(priceMessage);
});
}
我想能够收集的标志,日期,问题和答案,并通过电子邮件发送给他们example@gmail.com.更新1: 通过这种方式,您至少可以显示您的消息
displayVisuals(stringgra)
方法。移除其中一个李>
=>
displaySpeaker()方法中的setText()更改为getText()
onCreate()
方法和submitButton.setOnClickListener~
。添加以下内容:你能生成这个代码吗?我认为它不能被编译。 您必须将值设置为实例,而不是类本身
// ImageView.getDisplay();
coolLogo.getDisplay();
// EditText.setText(name);
nameField.setText(name);
// TextView.setText(adv);
advAnt.setText(adv);
我将ImageView、EditText和TextView更改为上述格式…我的代码中有一些错误,我不知道为什么…@Gifer,请更新您的问题。给我看一下你的错误代码。谢谢@Stanley Kou,我已经更新了它以包含当前的错误。谢谢@Stanley Kou,现在唯一用红色突出显示的是reviewOrderSummary,它说无法解析方法“reviewOrderSummary”。@Gifer你在MainActivity.java中有
reviewOrderSummary
方法!删除按钮widget中的xml中的android:onClick=“submit”实际上,我真的希望您编译此代码,我建议您在完成后删除此问题。这个问题只对你有用,对社区没有用处。
//displays how helpful were the visuals TextView
private void displayVisuals(String gra) {
TextView graPhics = (TextView) findViewById(R.id.visuals);
gra = graPhics.getText().toString();
// TextView.setText(gra);
graPhics.setText(gra);
}
private void displaySpeaker(String com) {
TextView comCat = (TextView) findViewById(R.id.speaker);
com = comCat.getText().toString();
// TextView.setText(com);
comCat.setText(com);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
submitButton = (Button) findViewById(R.id.submit_button);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText nameField = (EditText) findViewById(R.id.presentationName);
EditText recDay = (EditText) findViewById(R.id.date);
TextView comCat = (TextView) findViewById(R.id.speaker);
TextView menDar = (TextView) findViewById(R.id.recommend);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.rg);
EditText sugGest = (EditText) findViewById(R.id.suggestions);
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto: example@gmail.com")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_SUBJECT, "Presentation Review for: " + nameField.getText().toString());
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
String priceMessage = reviewOrderSummary(
"Logo", /* Logo is an image, and you printing string. Is that what you meant? */
nameField.getText().toString(),
recDay.getText().toString(),
comCat.getText().toString(),
true, /* rating_bar1_result is a TextView, and you printing boolean. Is that what you meant? */
"GRA", /* Indefinite */
true, /* rating_bar2_result is a TextView, and you printing boolean. Is that what you meant? */
"ADV", /* Indefinite */
true, /* rating_bar3_result is a TextView, and you printing boolean. Is that what you meant? */
menDar.getText().toString(),
radioGroup.getCheckedRadioButtonId() == 0,
sugGest.getText().toString()
);
displayMessage(priceMessage);
}
});
}
// ImageView.getDisplay();
coolLogo.getDisplay();
// EditText.setText(name);
nameField.setText(name);
// TextView.setText(adv);
advAnt.setText(adv);