Foros del Web » Programando para Internet » Android »

Obtener información de checkbox y EditText dentro de un LinearLayout

Estas en el tema de Obtener información de checkbox y EditText dentro de un LinearLayout en el foro de Android en Foros del Web. Tengo unos checkbox y editText que genero dinamicamente por medio de una consulta Este es el metodo que genere el checkbox y editText y lo ...
  #1 (permalink)  
Antiguo 28/04/2015, 14:27
Avatar de Maverick2786  
Fecha de Ingreso: diciembre-2012
Mensajes: 107
Antigüedad: 11 años, 4 meses
Puntos: 1
Obtener información de checkbox y EditText dentro de un LinearLayout

Tengo unos checkbox y editText que genero dinamicamente por medio de una consulta

Este es el metodo que genere el checkbox y editText y lo agrega al LinearLayout
Código Java:
Ver original
  1. private void create_form() {
  2.         JSONObject json = null;
  3.         int count = 0;
  4.         lm = (LinearLayout) findViewById(R.id.linearMain);
  5.         int seccion = Integer.parseInt(conf.get_id_seccion());
  6.         int tipo_solicitud = Integer.parseInt(conf.get_tipo_solicitud());
  7.         JSONObject jobj = obj_sqlite.get_form(seccion, tipo_solicitud);
  8.        
  9.  
  10.         try {
  11.             count = Integer.parseInt(jobj.getString("cont"));
  12.             json = new JSONObject(jobj.getString("json"));
  13.         } catch (Exception e) {
  14.             Log.e("getParams", e.getMessage());
  15.         }
  16.  
  17.         for (int x = 1; x <= count; x++) {
  18.  
  19.             try {
  20.                 JSONObject json_row = new JSONObject(json.getString("row" + x));
  21.                
  22.                 CheckBox chb = new CheckBox(this);
  23.                 chb.setText(json_row.getString("pregunta"));
  24.                 chb.setId(json_row.getInt("pregunta_verificacion_supervision"));
  25.                 chb.setTextSize(10);
  26.                 chb.setPadding(8, 3, 8, 3);
  27.                 chb.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
  28.                 chb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  29.                         LayoutParams.WRAP_CONTENT));
  30.  
  31.                 lm.addView(chb);
  32.                
  33.                 EditText et = new EditText(this);
  34.                 et.setHint("observaciones");
  35.                 et.setId(json_row.getInt("pregunta_verificacion_supervision"));
  36.                 et.setTextSize(10);
  37.                 et.setPadding(8, 3, 8, 3);
  38.                 et.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
  39.                 et.setInputType(android.text.InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
  40.                 et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
  41.                         LayoutParams.WRAP_CONTENT));
  42.  
  43.                 lm.addView(et);
  44.  
  45.                
  46.             } catch (Exception e) {
  47.                 Log.e("getParams", e.getMessage());
  48.             }
  49.         }
  50.     }

ahora necesito obtener todos los checkbox que esta seleccionados junto con su edittext para guardarlos en la tabla

este es mi xml
Código XML:
Ver original
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:tools="http://schemas.android.com/tools"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:paddingBottom="@dimen/activity_vertical_margin"
  6.    android:paddingLeft="@dimen/activity_horizontal_margin"
  7.    android:paddingRight="@dimen/activity_horizontal_margin"
  8.    android:paddingTop="@dimen/activity_vertical_margin"
  9.    tools:context="com.example.php_mysql_sqlite.Formulario_verificacion_supervision" >
  10.  
  11.     <TextView
  12.        android:layout_width="wrap_content"
  13.        android:layout_height="wrap_content"
  14.        android:text="@string/title_activity_preguntas_revision" android:id="@+id/textView1"/>
  15.    
  16.     <ScrollView
  17.        android:id="@+id/scrollView1"
  18.        android:layout_width="285dp"
  19.        android:layout_height="330dp"
  20.        android:layout_marginTop="30dp" >
  21.  
  22.         <LinearLayout
  23.            android:id="@+id/linearMain"
  24.            android:layout_width="fill_parent"
  25.            android:layout_height="fill_parent"
  26.            android:layout_alignParentTop="true"
  27.            android:background="@color/White"
  28.            android:orientation="vertical" >
  29.         </LinearLayout>
  30.     </ScrollView>
  31.  
  32.     <Button
  33.        android:id="@+id/bt_regresar"
  34.        style="?android:attr/buttonStyleSmall"
  35.        android:layout_width="wrap_content"
  36.        android:layout_height="wrap_content"
  37.        android:layout_alignParentBottom="true"
  38.        android:layout_alignRight="@+id/scrollView1"
  39.        android:onClick="regresar"
  40.        android:text="@string/bt_regresar" />
  41.  
  42.     <Button
  43.        android:id="@+id/bt_guardar"
  44.        style="?android:attr/buttonStyleSmall"
  45.        android:layout_width="wrap_content"
  46.        android:layout_height="wrap_content"
  47.        android:layout_alignBaseline="@+id/bt_finalizar"
  48.        android:layout_alignBottom="@+id/bt_finalizar"
  49.        android:layout_alignLeft="@+id/scrollView1"
  50.        android:text="@string/bt_guardar"
  51.        android:onClick="guardar" />
  52.  
  53.     <Button
  54.        android:id="@+id/bt_finalizar"
  55.        style="?android:attr/buttonStyleSmall"
  56.        android:layout_width="wrap_content"
  57.        android:layout_height="wrap_content"
  58.        android:layout_alignBaseline="@+id/bt_regresar"
  59.        android:layout_alignBottom="@+id/bt_regresar"
  60.        android:layout_marginLeft="31dp"
  61.        android:layout_toRightOf="@+id/bt_guardar"
  62.        android:text="@string/bt_finalizar"
  63.        android:onClick="finalizar" />
  64.  
  65. </RelativeLayout>

y esta es una imagen de como esta actualmente

por medio de un metodo que es llamado en un button click, hacer la accion de obtener los datos


Gracias a todos

pd: Si me dan puntos negativos, dejar un comentario del porque , ya que me ha pasado en el pasado y no se que hago mal

Etiquetas: activity, androi, checkbox, view
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:58.