mardi 28 avril 2015

Get information checkbox and EditText within a LinearLayout

I have a checkbox and EditText that generated dynamically by a query

This is the method that generates the checkbox and EditText and adds it to LinearLayout

private void create_form() {
    JSONObject json = null;
    int count = 0;
    lm = (LinearLayout) findViewById(R.id.linearMain);
    int seccion = Integer.parseInt(conf.get_id_seccion());
    int tipo_solicitud = Integer.parseInt(conf.get_tipo_solicitud());
    JSONObject jobj = obj_sqlite.get_form(seccion, tipo_solicitud);


    try {
        count = Integer.parseInt(jobj.getString("cont"));
        json = new JSONObject(jobj.getString("json"));
    } catch (Exception e) {
        Log.e("getParams", e.getMessage());
    }

    for (int x = 1; x <= count; x++) {

        try {
            JSONObject json_row = new JSONObject(json.getString("row" + x));

            CheckBox chb = new CheckBox(this);
            chb.setText(json_row.getString("pregunta"));
            chb.setId(json_row.getInt("pregunta_verificacion_supervision"));
            chb.setTextSize(10);
            chb.setPadding(8, 3, 8, 3);
            chb.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
            chb.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));

            lm.addView(chb);

            EditText et = new EditText(this);
            et.setHint("observaciones");
            et.setId(json_row.getInt("pregunta_verificacion_supervision"));
            et.setTextSize(10);
            et.setPadding(8, 3, 8, 3);
            et.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);
            et.setInputType(android.text.InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
            et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));

            lm.addView(et);


        } catch (Exception e) {
            Log.e("getParams", e.getMessage());
        }
    }
}

Now I need to get all this checkbox selected along with your EditText to keep them in the table

this is my xml

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.php_mysql_sqlite.Formulario_verificacion_supervision" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/title_activity_preguntas_revision" android:id="@+id/textView1"/>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="285dp"
    android:layout_height="330dp"
    android:layout_marginTop="30dp" >

    <LinearLayout
        android:id="@+id/linearMain"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:background="@color/White"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/bt_regresar"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/scrollView1"
    android:onClick="regresar"
    android:text="@string/bt_regresar" />

<Button
    android:id="@+id/bt_guardar"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/bt_finalizar"
    android:layout_alignBottom="@+id/bt_finalizar"
    android:layout_alignLeft="@+id/scrollView1"
    android:text="@string/bt_guardar"
    android:onClick="guardar" />

<Button
    android:id="@+id/bt_finalizar"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/bt_regresar"
    android:layout_alignBottom="@+id/bt_regresar"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/bt_guardar"
    android:text="@string/bt_finalizar"
    android:onClick="finalizar" />

and this is one image as is currently http://ift.tt/1QFYvRO

by a method that is called on a button click, making the action to get the data

Thanks to all

PS: If you give me negative points, leave a comment of that because it has happened to me in the past and can not do wrong




Aucun commentaire:

Enregistrer un commentaire