私は Android が初めてで、友人のために小さなアプリを作ろうとしています。このアプリには、人々が記入して送信できるフォームがあります。名前や住所などの情報が含まれています。フォームは完全に機能しますが、チェックしたラジオボタンからフォームに値を転送する方法がわかりません。
package com.example.x_pand;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class Bestilling extends Activity implements RadioGroup.OnCheckedChangeListener {
RadioGroup rg;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bestilling);
rg = (RadioGroup) findViewById(R.id.radio_group1);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
RadioButton r1 = (RadioButton) findViewById(R.id.radioButton1);
if(r1.isChecked())
{
Toast.makeText(getBaseContext(), "Afhentningsdag bliver næst kommende onsdag", Toast.LENGTH_LONG).show();
}
else
Toast.makeText(getBaseContext(), "Afhentningsdag bliver næst kommende fredag", Toast.LENGTH_LONG).show();
}
});
final EditText name = (EditText) findViewById(R.id.editText1);
final EditText addy = (EditText) findViewById(R.id.editText2);
final EditText city = (EditText) findViewById(R.id.editText3);
final EditText emaile = (EditText) findViewById(R.id.editText6);
final EditText post = (EditText) findViewById(R.id.editText5);
final EditText tlf = (EditText) findViewById(R.id.editText7);
Button mail = (Button) findViewById(R.id.send_form);
mail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
//TODO Auto-generated method stub
Intent email = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
email.setType("plain/text");
email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"test@mydomain.dk"});
email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Bestilling til x-pand");
email.putExtra(android.content.Intent.EXTRA_TEXT,
"Navn: "+name.getText().toString()+'\n'+"Adresse: "+addy.getText().toString()+'\n'+"By: "+city.getText().toString()+ '\n'+"E-mail: "+emaile.getText().toString()+'\n'+"Tlf: "+tlf.getText().toString()+'\n'+"Post nr.: "+post.getText().toString()+'\n'+'\n'+"Bestilling til x-pand");
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(email, "Send mail..."));
}
});
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
}
}