android - Get information checkbox and EditText within a LinearLayout -
i have checkbox , edittext generated dynamically query
this method generates checkbox , edittext , adds 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()); } (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 need checkbox selected along edittext keep them in table
this xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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 1 image http://i61.tinypic.com/2uo2hi8.jpg
by method called on button click, making action data
thanks all
ps: if give me negative points, leave comment of because has happened me in past , can not wrong
you have 2 options.
set unique id each checkbox , edittext , keep ids in arraylist. when want check
for(int = 0 ; < listofcboxids.size() ; ++i) { checkbox cbox = (checkbox) findviewbyid(listofcboxids.get(i)); if(cbox.ischecked()) { // } }keep references checkboxes , edittexts in arraylist , iterate on it. less cpu intensive.
list<checkbox> yourcheckboxes = new arraylist<checkbox>(); list<edittext> youredittexts = new arraylist<edittext>(); 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); yourcheckboxes.add(chb); youredittexts.add(et); } catch (exception e) { log.e("getparams", e.getmessage()); }
once need them
for(int = 0 ; < yourcheckboxes.size() ; ++i) { checkbox cbox = (checkbox) yourcheckboxes.get(i); edittext et = (edittext) youredittexts.get(i); if(cbox.ischecked()) { // } }
Comments
Post a Comment