我的应用程序有一个大问题,我已经来到这里,我学会了如何创建数据库以及如何插入单选按钮和编辑文本值,现在我要做的是插入两个单选按钮的选定值并在单击按钮(添加)时编辑文本,但我面临一个问题,即不考虑值编辑文本,如果有人帮助我,我将不胜感激!这是代码:
public long insertMENAGE(String Region, String Provence_prefecture , String Commune_Arrondissement ,String N_district, String N_M_district, int echantillon_principal, int Statut_enquêté ) {
ContentValues initialValues = new ContentValues();
initialValues.put(col_Region,Region);
initialValues.put(col_Provence_prefecture ,Provence_prefecture);
initialValues.put(col_Commune_Arrondissement,Commune_Arrondissement);
initialValues.put(col_N_district,N_district);
initialValues.put(col_N_M_district,N_M_district);
initialValues.put(col_echantillon_principal,echantillon_principal);
initialValues.put(col_Statut_enquêté,Statut_enquêté);
return db.insert(MENAGE,null, initialValues);
}
public class ActivityUn extends Activity {
DBAdapter db = new DBAdapter(this);
public void ajouter(View v) {
db.open();
db.insertMENAGE(rm_1ts,rm_2ts,rm_3ts,rm_4ts,rm_5ts,a,b);
db.close();
}
private RadioGroup rm_13;
private RadioButton rm_13_1 ;
private RadioButton rm_13_2 ;
private RadioGroup rm_14;
private RadioButton rm_14_1 ;
private RadioButton rm_14_2 ;
private RadioButton rm_14_3;
private RadioButton rm_14_4 ;
int a;
int b;
EditText rm_1;
EditText rm_2;
EditText rm_3 ;
EditText rm_4 ;
EditText rm_5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_un);
String rm_1ts = rm_1.getText().toString();
String rm_2ts = rm_2.getText().toString();
String rm_3ts = rm_3.getText().toString();
String rm_4ts = rm_4.getText().toString();
String rm_5ts = rm_5.getText().toString();
Button suivant = (Button)findViewById(R.id.activityDeux);
suivant.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent l = new Intent(ActivityUn.this,ActivityDeux.class);
startActivity(l);
}
});
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.rm_13_1:
if (checked)
a=0;
break;
case R.id.rm_13_2:
if (checked)
a=1;
break;
case R.id.rm_14_1:
if (checked)
b=0;
break;
case R.id.rm_14_2:
if (checked)
b=1;
break;
case R.id.rm_14_3:
if (checked)
b=2;
break;
case R.id.rm_14_4:
if (checked)
b=3;
break;
}
Button bton = (Button)findViewById(R.id.ajoutUn);
bton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ajouter(v);
Toast.makeText(getApplicationContext(), "Données Enregistrées", Toast.LENGTH_SHORT).show();
}
});
}
}