-1

我有四个文本框,我希望当它们被选中时,它们会根据我的电子邮件意图发送一个文本值。例如,如果选择了“我检查了电视”文本框,邮件中会显示“电视已检查”。这是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"));         
        }}}
4

1 回答 1

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(); 从中。

干杯!

于 2013-07-27T21:32:25.477 回答