我有四个文本框,我希望在检查时,他们会根据我的电子邮件意图发送文本值。例如,如果选中“我检查了电视”文本框,则在邮件中显示“电视已被检查”。这是java代码:
package com.example.kapscht;
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.CheckBox;
import android.widget.EditText;
import android.view.View.OnClickListener;
public class MainActivity extends Activity implements OnClickListener{
CheckBox checkcable;
CheckBox checkmodulo;
CheckBox checkantena ;
CheckBox checkampli ;
EditText etlugar;
EditText etfecha;
EditText etcable;
EditText etantena;
EditText etampli;
EditText etmodulo;
EditText etqe;
String l= "Lugar:";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etlugar = (EditText) findViewById(R.id.etlugar);
etfecha = (EditText) findViewById(R.id.etfecha);
etcable = (EditText) findViewById(R.id.etcable);
etantena = (EditText) findViewById(R.id.etantena);
etampli = (EditText) findViewById(R.id.etampli);
etmodulo = (EditText) findViewById(R.id.etmodulo);
etqe = (EditText) findViewById(R.id.etqe);
checkcable = (CheckBox) findViewById(R.id.checkcable);
checkmodulo = (CheckBox) findViewById(R.id.checkmodulo);
checkantena = (CheckBox) findViewById(R.id.checkantena);
checkampli = (CheckBox) findViewById(R.id.checkampli);
View boton = (Button) findViewById(R.id.enviar);
boton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId()==findViewById(R.id.enviar).getId())
{
Intent intentEmail = new Intent(Intent.ACTION_SEND, Uri.fromParts("mailto", "villasantdesign@gmail.com", null));
intentEmail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"villasantdesign@gmail.com"});
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "Consulta Técnica");
intentEmail.putExtra(Intent.EXTRA_TEXT, "Lugar:"+etlugar.getText()+"\nFecha: "+etfecha.getText()+"\nComentarios módulo:"+etmodulo.getText()+"\nComentarios Antena: "+etantena.getText()+"\nComentarios cable:"+etcable.getText()+"\nComentarios Amplificador: "+etampli.getText()+"\nEnviado por: "+etqe.getText());
intentEmail.setType("message/rfc822");
startActivity(Intent.createChooser(intentEmail, "Enviar"));
}}}
答案 0 :(得分:0)
在你的布局main.xml中包含它
<CheckBox android:id="@+id/someid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="youClickedMe"/>
在MainActivity中创建方法
public void youClickedMe(View view){
System.out.println("You clicked check box");
}
完成..如果你想获得一个值,你需要在方法中找到id的视图然后getText();从它。
干杯!