2017-03-06 43 views
0

我的情况是下一个。当您可以进行调查时,我正在创建一个应用程序,然后,您可以在应用程序中看到调查答案,单击按钮,而无需转到电话文件或类似的东西。我创建了55%的应用程序,但其他45%是最重要的。有多少可能性,或者我能做些什么来实现这一点,当一个人点击一个应用内按钮时,可以看到调查答案。我做了界面,按钮,textview等。我创建了一个数据库,减轻了创建它,这将有可能实现我想要的。我希望在做一个调查时做一个系统,然后按下一个按钮,打开一个新的活动并查看调查答案。当您关闭应用程序并再次打开时,调查答案不会消失,它们仍会保存。谢谢!用户在手机上创建的存储数据。请看这个帖子

这里是我的调查,XML和Java代码:

Button sig = (Button) findViewById(R.id.env); // cargo el boton 
    encuestadoSQLiteHelper encuestado = new encuestadoSQLiteHelper(this, "DBEncuestado", null, 1); // base de datos 
    final SQLiteDatabase db = encuestado.getWritableDatabase(); 


    sig.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Context context = getApplicationContext(); 
      EditText preg5 = (EditText) findViewById(R.id.editText2); 
      EditText preg4 = (EditText) findViewById(R.id.editText); 
      Spinner cur = (Spinner) findViewById(R.id.spinnerp); 
      EditText nom = (EditText) findViewById(R.id.editText3); 
      RadioGroup gruporadio = (RadioGroup) findViewById(R.id.Grupo1); 
      RadioGroup gruporadio2 = (RadioGroup) findViewById(R.id.Grupo2); 
      RadioGroup gruporadio3 = (RadioGroup) findViewById(R.id.Grupo3); 
      String strNombre = nom.getText().toString(); 
      String nombre = "PabloGonzalez"; 
      String curso = cur.getSelectedItem().toString(); 
      String strPregCinco = preg5.getText().toString(); 
      String strPregCuatro = preg4.getText().toString(); 

      if(gruporadio.getCheckedRadioButtonId() == -1 || gruporadio2.getCheckedRadioButtonId() == -1 || gruporadio3.getCheckedRadioButtonId() == -1) 
      { 
       Toast.makeText(context,"¡No marcaste ninguna respuesta!",Toast.LENGTH_LONG).show(); 
      } 

      else if (strNombre.matches("") || strPregCinco.matches("") || strPregCuatro.matches("")) 
      { 
       Toast.makeText(context,"¡Dejaste campos vacíos!",Toast.LENGTH_LONG).show(); 
      } 

      else if(db == null) 
      { 
       Toast.makeText(context, "No funciona la base de datos.", Toast.LENGTH_LONG).show(); 
       db.close(); 
      } 

      else 
      { 
       Intent i = new Intent (encuesta.this, res8.class); 
       i.putExtra("nombre", strNombre); 
       startActivity(i); 
       Intent pas = new Intent(encuesta.this, MainActivity.class); 
       Toast.makeText(context,"¡Encuesta enviada!",Toast.LENGTH_LONG).show(); 
       startActivity(pas); 
       db.execSQL("INSERT INTO Encuestado (nombre) " + 
         "VALUES ('" + nombre +"')"); 
       db.close(); 
       new Thread(new Runnable() { 
        @Override 
        public void run() { 
         try { 
          File sd = Environment.getExternalStorageDirectory(); 
          File data = Environment.getDataDirectory(); 

          if (sd.canWrite()) { 
           String currentDBPath = "/data/com.example.pablo.myapplication/databases/DBEncuestad‌​o"; 
           String backupDBPath = "backdatabase.sqlite"; 
           File currentDB = new File(data, currentDBPath); 
           File backupDB = new File(sd, backupDBPath); 

           if (currentDB.exists()) { 
            FileChannel src = new FileInputStream(currentDB).getChannel(); 
            FileChannel dst = new FileOutputStream(backupDB).getChannel(); 
            dst.transferFrom(src, 0, src.size()); 
            src.close(); 
            dst.close(); 
           } 
          } 
         } catch (Exception e) { 
          System.out.println("error in data base copy:"+e); 
         } 
        } 
       }).start(); 
      } 
     } 
    }); 

} 

}

如果你能看到,有一个数据库,但我不知道,如果没有必要还是有的。

XML:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TextView 
     android:text="Nombre del encuestado:" 
     android:id="@+id/nomb" 
     android:textSize="16dp" 
     android:textColor="#000000" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/editText3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="2dp" 
     android:layout_marginTop="2dp" 
     android:ems="15" 
     android:inputType="textPersonName" 
     android:text="" /> 

    <TextView 
     android:text="Curso:" 
     android:textSize="16dp" 
     android:textColor="#000000" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <Spinner 
     android:id="@+id/spinnerp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp"/> 

    <TextView 
    android:text="1. ¿Cuánto tiempo tarda usted desde su casa al colegio?" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textSize="16dp" 
    android:textColor="#000000" 
    android:id="@+id/textView" /> 



    <RadioGroup 
     android:id="@+id/Grupo1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <RadioButton 
      android:id="@+id/radioButton" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="1/2 hora a 1 hora" /> 

     <RadioButton 
      android:id="@+id/radioButton1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="1 hora o 2 horas" /> 

     <RadioButton 
      android:id="@+id/radioButton2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="2 horas o más" /> 
    </RadioGroup> 

<TextView 
    android:text="2. ¿Cuánto tiempo tarda desde el colegio a su casa?" 
    android:layout_marginTop="20dp" 
    android:textSize="16dp" 
    android:textColor="#000000" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

    <RadioGroup 
     android:id="@+id/Grupo2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <RadioButton 
      android:id="@+id/radioButton3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="1/2 hora a 1 hora" /> 

     <RadioButton 
      android:id="@+id/radioButton4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="1 hora o 2 horas" /> 

     <RadioButton 
      android:id="@+id/radioButton5" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="2 horas o más" /> 
    </RadioGroup> 

<TextView 
    android:text="3. ¿Cuáles de las siguientes zonas de Bogotá está localizado su domicilio?" 
    android:layout_marginTop="20dp" 
    android:textSize="16dp" 
    android:textColor="#000000" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView2" /> 

    <RadioGroup 
     android:id="@+id/Grupo3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     <RadioButton 
     android:id="@+id/radioButton6" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Norte de Bogotá (calle 72 en adelante)" /> 

     <RadioButton 
      android:id="@+id/radioButton7" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Suba (noroccidente)" /> 

     <RadioButton 
      android:id="@+id/radioButton8" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Centro - Chapinero - Teusaquillo" /> 

     <RadioButton 
      android:id="@+id/radioButton9" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Alrededores de Bogotá" /> 

     <RadioButton 
      android:id="@+id/radioButton10" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Sur de Bogotá" /> 

     <RadioButton 
      android:id="@+id/radioButton11" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Occidente (Puente Aranada - Fontibón - Engativá)" /> 
    </RadioGroup> 


<TextView 
    android:text="4. Si usted fuera alcalde de Bogotá, ¿que solución propondría para mejorar la movilidad de Bogotá?" 
    android:textColor="#000000" 
    android:textSize="16dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:id="@+id/textView3" /> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="13dp" 
     android:background="#e4e4e4" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:paddingBottom="8dp" 
     android:paddingLeft="10dp" 
     android:paddingTop="2dp" 
     android:textSize="16dp" /> 

<TextView 
    android:text="5. ¿Cómo cree que influye la movilidad en la calidad de vida de las personas?" 
    android:textColor="#000000" 
    android:textSize="16dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:id="@+id/textView4" 
    android:layout_below="@+id/editText" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="20dp" 
     android:background="#e4e4e4" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:paddingBottom="8dp" 
     android:paddingLeft="10dp" 
     android:paddingTop="2dp" 
     android:textSize="16dp" /> 

    <Button 
     android:text="Enviar encuesta" 
     android:textSize="14dp" 
     android:id="@+id/env" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    </LinearLayout> 
</ScrollView> 

和活动,我想表现出的答案是res8.java

+0

你做了什么,你想做什么,你如何期望做你想做的事情? – nandsito

+0

我做了界面,按钮,textview等。我创建了一个数据库,thiniking创建它,有可能实现我想要的。我希望在做一个调查时做一个系统,然后按下一个按钮,打开一个新的活动并查看调查答案。当您关闭应用程序并再次打开时,调查答案不会消失,它们仍会保存。 –

+0

我建议你更新你的问题与你的持久性实现的细节,所以你可以让你的数据库工作 – nandsito

回答

0

兄弟,就创建像getter和setter先有像getQuestion(),setQuestion方法模型类(),getAnswer(),setAnswer()。而在这之后,当用户回答您的调查问题刚刚创建的模型类的对象说,如: -

ArrayList<MyModel> datalist = new ArrayList(); 
    MyModel model = new MyModel(); 
    model.setQuestion(list.get(i).question); 
    model.setAnswer(list.get(i).answer); 
    .... 
    .... 
    dataList.add(model); 

这样刚刚捕获所有的用户输入数据,没有必要在这个数据库中。

下面列表是你有所有问题的列表....

而当你想的getData ...只是调用datalist.get(I).getQuestion,同样有答案。

+0

我该如何使用我在该问题上发布的代码来做到这一点? –

相关问题