Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从asynctask动态生成的EditText、复选框、Radiobutton在数据库中保存数据?_Php_Android_Mysql_Mobile_Survey - Fatal编程技术网

Php 从asynctask动态生成的EditText、复选框、Radiobutton在数据库中保存数据?

Php 从asynctask动态生成的EditText、复选框、Radiobutton在数据库中保存数据?,php,android,mysql,mobile,survey,Php,Android,Mysql,Mobile,Survey,我有一个Android的数字调查应用程序,我的应用程序从服务器(mysql php)获取数据并在活动中显示。我的疑问是如何将de数据保存到数据库中,因为我动态生成了问题和答案选项 下面是Activity类的代码 public void onPostExecute(String result) { pDialog.dismiss();//ocultamos progess dialog. //paring data String id

我有一个Android的数字调查应用程序,我的应用程序从服务器(mysql php)获取数据并在活动中显示。我的疑问是如何将de数据保存到数据库中,因为我动态生成了问题和答案选项

下面是Activity类的代码

       public void onPostExecute(String  result) {

       pDialog.dismiss();//ocultamos progess dialog.


       //paring data
       String id_preg;
        String preg;
        String tipopreg;
        String tipo_opc;
        String descri_op;
        String id_pregunta = null;
        String pregunta = null;
        String tipo_pregunta = null;
        String tipo_opcion = null;
        String descrip_opc;

        try{
            JSONArray jArray = new JSONArray(result);
        JSONObject json_data=null;
     String[] tipopregu=new String[jArray.length()];
      String[] tipopcion=new String[jArray.length()];
      String[] id_preguntas=new String[jArray.length()];
      String[] descripcion_opc=new String[jArray.length()];     
    String aux1="";
    String aux2="";
    String aux3="";
    String aux4="";
    String auxtipoopc;
    int cont=1;
    int cont2=0;
    //validate the values not repeteated because 
      for(int i=0;i<jArray.length();i++){


                json_data = jArray.getJSONObject(i);
                //Get DAta
                id_preg =json_data.getString("ID_PREGUNTA");//IS QUESTION ID
                preg = json_data.getString("DESCRIPCION");//DESCRIPTION
               tipopreg=json_data.getString("TIPO_PREGUNTA");   //TYPE OF                               QUESTION
               tipo_opc=json_data.getString("ID_TIPOOPC");//VALUE OF ID TYPE OPTION
               auxtipoopc=tipo_opc;
                descrip_opc=json_data.getString("DESCRIP_OPC");//DESCRIPTION OF VALUES USED IN MULTIPLES VALUES
         if((!aux1.equals(id_preg))||(!aux2.equals(preg))||(!aux3.equals(tipopreg))||(!aux4.equals(tipo_opc)) ){
                id_pregunta=id_preg;
                pregunta=preg;
                tipo_pregunta=tipopreg;
                tipo_opcion=tipo_opc;
                nameValuePairs.add(new list<String, String>(id_pregunta, pregunta));
                id_preguntas[cont2]=id_pregunta;
                tipopregu[cont2]=tipo_pregunta;
                tipopcion[cont2]=tipo_opcion;
                Log.e("id_pregunta", id_pregunta);

                Log.e("pregunta",pregunta);
                    Log.e("id_preg-pregunta", id_pregunta+" "+pregunta);
                    Log.e("tipo_pregunta",tipo_pregunta);



                Log.e("tipo_opc",tipo_opcion);

                cont2=cont2+1;
                Log.e("contador2",String.valueOf(cont2));
         }


                descripcion_opc[i]=descrip_opc;
             nameValuePairs2.add(new list<String, String>(auxtipoopc, descrip_opc));   
             Log.e("Id_tipo_opc--Opcion", auxtipoopc+" "+descrip_opc);  
             aux1=id_preg;
                aux1=preg;
                aux3=tipopreg;
                aux4=tipo_opc;

             cont=cont+1;
          Log.e("contador1",String.valueOf(cont));
        }
     List<NameValuePair> datos = new ArrayList<NameValuePair>();
        datos=nameValuePairs;



    List<EditText> allEds = new ArrayList<EditText>();

    llinear=(LinearLayout) findViewById(R.id.preg);

    final int N=cont2+1;
    final TextView[] tx = new TextView[N];
            int j=0;        
    for (NameValuePair i:nameValuePairs) {


        String id_preguntastr=i.getName();
        String preguntastr=i.getValue();
        String tipopregun=tipopregu[j];
        String id_opcion=tipopcion[j];
        String id_preguntaaux=id_preguntas[j];

        final  TextView rowTextView = new TextView(getBaseContext());
        rowTextView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        rowTextView.setText(id_preguntastr+"   "+preguntastr);



        llinear.addView(rowTextView);
        tx[j] = rowTextView;



        if(tipopregun.equals("SI-NO"))// IF QUESTION IS YES/NO
        {
             RadioGroup radiogroup1 = new RadioGroup(getBaseContext());
            final  RadioButton rowradiobuttsi = new RadioButton(getBaseContext());
            rowradiobuttsi.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            rowradiobuttsi.setText("SI");
            radiogroup1.addView(rowradiobuttsi);
            final  RadioButton rowradiobuttno = new RadioButton(getBaseContext());
            rowradiobuttno.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            rowradiobuttno.setText("NO");

               radiogroup1.addView(rowradiobuttno);
             llinear.addView(radiogroup1) ; 

        }
        if(tipopregun.equals("Verdadero-Falso"))//IF QUESTION IS TYPE TRUE/FALSE    
        {   
             RadioGroup radiogroup2 = new RadioGroup(getBaseContext());
                final  RadioButton rowradiobuttv = new RadioButton(getBaseContext());
                rowradiobuttv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                rowradiobuttv.setText("VERDADERO");
                radiogroup2.addView(rowradiobuttv);
                final  RadioButton rowradiobuttf = new RadioButton(getBaseContext());
                rowradiobuttf.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                rowradiobuttf.setText("FALSO");

                   radiogroup2.addView(rowradiobuttf);
                 llinear.addView(radiogroup2) ; 
        }

        if(tipopregun.equals("Valor"))  //IF QUESTION IS A VALUE(EDITTEXT)
        {




           //count is number of edittext fields
            final EditText ed = new EditText(getBaseContext());
        ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        allEds.add(ed);

        llinear.addView(ed);

        }

        if(tipopregun.equals("opcionmultiple"))//MULTIPLE OPTIONS (CHECKBOXs)
        {

            for (NameValuePair k:nameValuePairs2) {
                String tipoopcion=k.getName();
                String opcion=k.getValue();

                if(tipoopcion.equalsIgnoreCase("3")){


                final  CheckBox checkboxoptionsm = new CheckBox(getBaseContext());
                checkboxoptionsm.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                checkboxoptionsm.setText(opcion);
                allChbx.add(checkboxoptionsm);
                llinear.addView(checkboxoptionsm);
                }
            }

                }

        j=j+1;
    }



        }catch(JSONException e4){
            Toast.makeText(getBaseContext(), "Preguntas no Encontrada"+e4, Toast.LENGTH_LONG).show();
             Log.e("fallo", "fallo", e4);
         // Log.e("pairs",nameValuePairs);
        }
        catch(Exception e9){
            Log.e("error", String.valueOf(e9));
        }



   }
public void onPostExecute(字符串结果){
pDialog.disclose();//ocultamos进程对话框。
//配对数据
字符串id_preg;
字符串preg;
字符串tipopreg;
字符串tipo_opc;
字符串描述;
字符串id_pregunta=null;
字符串pregunta=null;
字符串tipo_pregunta=null;
字符串tipo_opcion=null;
字符串描述;
试一试{
JSONArray jArray=新JSONArray(结果);
JSONObject json_data=null;
String[]tipopregu=新字符串[jArray.length()];
String[]tipopcion=新字符串[jArray.length()];
String[]id_preguntas=新字符串[jArray.length()];
String[]description_opc=新字符串[jArray.length()];
字符串aux1=“”;
字符串aux2=“”;
字符串aux3=“”;
字符串aux4=“”;
字符串AUXTIPOPC;
int cont=1;
int cont2=0;
//验证不重复的值,因为

对于(int i=0;i您可以重新捕获从用户收集的答案,并将它们发送回服务器,以便使用您在此处使用的Http客户端请求和namevaluepairs进行数据库处理。

您可以反序列化问题和显示问题的选项。因此,您将能够以相反的方式序列化它们。