1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package com.example.formulaire;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.Toast;
import android.telephony.SmsManager;
import android.view.View.OnClickListener;
public class Formulaire extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulaire);
//récupération des champs grace a leurs id
EditText editText1 = (EditText) findViewById (R.id.editTextnom);
EditText editText2 = (EditText) findViewById (R.id.editTextprenom);
EditText editText3 = (EditText) findViewById (R.id.editTextmail);
//récupération des boutons grace à leurs id
RadioGroup radioGroupsex = (RadioGroup) findViewById (R.id.radioGroupsex);
final RadioButton masculin = (RadioButton) findViewById (R.id.radiomasculin);
final RadioButton feminin = (RadioButton) findViewById (R.id.radiofeminin);
RadioGroup radioGroupoperateur = (RadioGroup) findViewById (R.id.radioGroupoperateur);
RadioButton only = (RadioButton) findViewById (R.id.radioonly);
final RadioButton orange = (RadioButton) findViewById (R.id.radioorange);
final RadioButton sfr = (RadioButton) findViewById (R.id.radiosfr);
Button bouton = (Button) findViewById (R.id.buttonenvoyer);
//Récupartion de la ville
Spinner spinnerville = (Spinner) findViewById(R.id.spinnerville);
final String operat;
//récuperer le sexe
radioGroupsex.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
if ((RadioButton) findViewById (checkedId) == masculin )
{String sex = masculin.getText().toString();}
else
{String sex = feminin.getText().toString();}
}
});
//récupèrer l'opérateur
radioGroupoperateur.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
if ((RadioButton) findViewById (checkedId) == orange )
{String operat = orange.getText().toString();}
else
if ((RadioButton) findViewById (checkedId) == sfr )
{String operat = sfr.getText().toString();}
else
{Toast.makeText(Formulaire.this, "Ce service n'est pas encore disponible",Toast.LENGTH_SHORT).show();}
}
});
//récupere la ville
String villechoisie = spinnerville.getSelectedItem().toString();
//on met un ecouteur sur le bouton envoyer
bouton.setOnClickListener(this.OnClickListener()
{
@Override
@SuppressWarnings("deprecation")
public void onClick(View v)
{
String inscription;
String sex;
SmsManager.getDefault().sendTextMessage(operat, null, inscription +" "+ editText1 + " "+editText2 + " " + editText3 + " " + sex + " " + villechoisie, null, null);
}
};
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_formulaire, menu);
return true;
}
} |
Partager