1

我的应用程序有一个大问题,我已经来到这里,我学会了如何创建数据库以及如何插入单选按钮和编辑文本值,现在我要做的是插入两个单选按钮的选定值并在单击按钮(添加)时编辑文本,但我面临一个问题,即不考虑值编辑文本,如果有人帮助我,我将不胜感激!这是代码:

      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();
             }


        });


}

}

4

1 回答 1

0

将所有类ActivityUn代码替换为

public class ActivityUn extends Activity {

//DB Class
DBAdapter db = new DBAdapter(this); 

//Execute Save Values
 public void  ajouter(View v) {
     db.open(); 
     db.insertMENAGE(rm_1ts,rm_2ts,rm_3ts,rm_4ts,rm_5ts,a,b);
     db.close();
} 

//Register Radio Group
RadioGroup rm_13,rm_14;

//Register Radio Button's
RadioButton rm_13_1,rm_13_2,rm_14_1,rm_14_2,rm_14_3,rm_14_4 ;


   int a = 0,
       b = 0;

//Register Edit Text
EditText  rm_1,rm_2,rm_3,rm_4,rm_5;

//Now Register Empty Values     
  String rm_1ts = "",
         rm_2ts = "",
         rm_3ts = "",
         rm_4ts = "",
         rm_5ts = "";


/****************************************
*Activity Created we need to Register All layouts or we will get Errors
*/        
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_un);


//Register Edit Texts
rm_1 = ( EditText ) findViewById(R.id.rm_1);
rm_2 = ( EditText ) findViewById(R.id.rm_2);
rm_3 = ( EditText ) findViewById(R.id.rm_3);    
rm_4 = ( EditText ) findViewById(R.id.rm_4);
rm_5 = ( EditText ) findViewById(R.id.rm_5);

//Register Radios
rm_13_1 = ( RadioButton ) findViewById(R.id.rm_13_1);
rm_13_2 = ( RadioButton ) findViewById(R.id.rm_13_2);
rm_14_1 = ( RadioButton ) findViewById(R.id.rm_14_1);
rm_14_2 = ( RadioButton ) findViewById(R.id.rm_14_2);
rm_14_3 = ( RadioButton ) findViewById(R.id.rm_14_3);
rm_14_4 = ( RadioButton ) findViewById(R.id.rm_14_4);

//Register Radio Groups, you dont have to do that if you don't using them
rm_13 = ( RadioGroup ) findViewById(R.id.rm_13);
rm_14 = ( RadioGroup ) findViewById(R.id.rm_14);

    //Button to start new Activity
    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);

           }});

//Button to Save information
((Button)findViewById(R.id.ajoutUn)).setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {

//Get EditText Values and Add them to the Strings started as blank Strings above
   rm_1ts = rm_1.getText().toString();
   rm_2ts = rm_2.getText().toString();
   rm_3ts = rm_3.getText().toString();
   rm_4ts = rm_4.getText().toString();
   rm_5ts = rm_5.getText().toString(); 

//Execute save info
ajouter(v);

Toast.makeText(getApplicationContext(), "Données Enregistrées", Toast.LENGTH_SHORT).show(); 

}});

}


        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;
                    }

        }
于 2013-11-03T22:26:57.207 回答