Las filas añadidas dinámicamente en tablelayout no son visibles
Tengo una tabla con la fila del jefe diseñada en xml. Ahora quiero agregar datos en la tabla (que obtengo de json array). Tengo que desplazar las filas de datos verticalmente sin afectar la fila de encabezado, por lo que creé otro cuadro de tabla justo debajo de la tabla de fila de encabezado. Luego, para cada campo de cada nueva fila, establezco parámetros de diseño en el archivo java y luego agrego la fila al segundo diseño de la tabla. Pero no hay filas visibles mientras los datos se están imprimiendo en el registro. No puedo averiguar dónde está mi error.
XML:
- ¿Cuál es el equivalente de "colspan" en un Android TableLayout?
- Edición de la anchura de TableLayout de Android
- Cómo agregar editText.addTextChangedListener en TableLayout
- Problemas de la suma de peso de TableLayout
- implementar android: stretchColumns = "*" programatically en Android
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TableLayout android:id="@+id/rv_table_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:id="@+id/rv_head_row" > <TextView android:id="@+id/rv_head_desc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/Desc" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/rv_head_unit" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/Unit" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/rv_head_type" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/Type" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/rv_head_range" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/Range" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/rv_head_rv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/RV" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/rv_head_remarks" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#999" android:gravity="center_horizontal|center_vertical" android:maxLines="1" android:padding="15dp" android:text="@string/Remarks" android:textSize="18sp" android:textStyle="bold" /> </TableRow> </TableLayout> <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"> <TableLayout android:id="@+id/rv_data_table_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> </TableLayout> </ScrollView> </LinearLayout>
CÓDIGO JAVA:
protected void onCreate(Bundle savedInstanceState) { Log.i("result value","in result value"); super.onCreate(savedInstanceState); setContentView(R.layout.results_value); /* * connecting with xml */ rv_table = (TableLayout) findViewById(R.id.rv_table_layout); rv_data_table = (TableLayout) findViewById(R.id.rv_data_table_layout); rv_head_row = (TableRow) findViewById(R.id.rv_head_row); desc = (TextView)findViewById(R.id.rv_head_desc); unit= (TextView)findViewById(R.id.rv_head_unit); type= (TextView)findViewById(R.id.rv_head_type); range = (TextView)findViewById(R.id.rv_head_range); rv= (TextView)findViewById(R.id.rv_head_rv); remarks= (TextView)findViewById(R.id.rv_head_remarks);; /* * getting data from server */ final Bundle extras = getIntent().getExtras(); try { js = new JSONObject(){ { put("CaseId", extras.getString("CaseId")); } }; } catch (JSONException e1) { e1.printStackTrace(); } Log.v("~~~~~===data is", js.toString()); service = new Services(ResultValueActivity.this); String rslt=service.getResultValue(js); try { JSONObject rs=new JSONObject(rslt); String p = rs.get("d").toString(); // this is done to // remove // starting d: ie seprating // first key value pairs JSONObject temp = new JSONObject(p); values = temp.getJSONArray("Table"); // values is a array of JSON } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* * data received, now starting filling values from json array to table */ JSONObject test; TableRow row; TextView desc1,unit1,type1,range1; EditText rv1; Button remarks1; for(int i=0;i<values.length();i++) { try{ test = values.getJSONObject(i); row = new TableRow(ResultValueActivity.this); desc1 = new TextView(ResultValueActivity.this); unit1 = new TextView(ResultValueActivity.this); type1 = new TextView(ResultValueActivity.this); range1 = new TextView(ResultValueActivity.this); rv1 = new EditText(ResultValueActivity.this); remarks1 = new Button(ResultValueActivity.this); /* * setting text in fields */ desc1.setText(test.getString("Description")); unit1.setText(test.getString("Unit")); type1.setText(test.getString("ResultType")); range1.setText(test.getString("RangeValue")); rv1.setText(test.getString("ResultValue")); remarks1.setText("Remarks"); desc1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); unit1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); type1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); range1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); rv1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); remarks1.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); row.setLayoutParams(new TableRow.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,1.0f)); Log.i(i+" result value test====>", test.toString()); row.addView(desc1); row.addView(unit1); row.addView(type1); row.addView(range1); row.addView(rv1); row.addView(remarks1); rv_data_table.addView(row,new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); rv_data_table.setVisibility(View.VISIBLE); Log.i(i+" desc value test====>", desc1.getText().toString()); Log.i(i+" unit value test====>", unit1.getText().toString()); } catch(JSONException jse) { jse.printStackTrace(); }} Log.i("result Value"," it is done :D :D"); }
El registro está imprimiendo todos los valores con precisión
- ¿Cómo hacer un TableLayout desplazable?
- ¿Cómo funciona android: shrinkColumns y android: stretchColumns?
- Las vistas agregadas a TableLayout no se muestran mediante programación
- Cómo ampliar Android TableLayout
- Cómo crear una paginación para el diseño de tabla dinámicamente creado con el conjunto visible?
- ¿Cómo obtener el evento de clic de la fila de la tabla / elemento de la tabla?
- Línea de encabezado de TableLayout de Android
- Crear un diseño chatView en android
El diseño de la primera tabla tiene altura de match_parent y, por lo tanto, no estaba dando espacio al diseño de la segunda tabla, así que lo cambié para envolver el contenido
- Desaparecidos constructores por defecto
- AlertDialog MultiChoiceItems – Seleccionando 2 elementos solo a la vez