-1

I'm using TableLayout. TableRows are dynamically added from the JSON parsing. I'm using Volley method for JSON Parsing. My problem is when I run the app at first time table rows are created. If I back to the tablelayout activity or redirect to the activity, table rows are not created.

tableRow5 = new TableRow(getApplicationContext());
                            tableRow5.setLayoutParams(new 
TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, 
TableLayout.LayoutParams.WRAP_CONTENT));

                            value5 = new TextView(getApplicationContext());
                            value5.setLayoutParams(textView5.getLayoutParams());
                            //value5.setGravity(Gravity.CENTER_HORIZONTAL);
                            value5.setText(String.valueOf(i+1));
                            value5.setTextColor(Color.parseColor("#1a73b7"));
                            value5.setHeight(60);
                            value5.setGravity(Gravity.CENTER);
                            tableRow5.addView(value5);


                            value5 = new TextView(getApplicationContext());
                            value5.setLayoutParams(textView5.getLayoutParams());
                            //value5.setGravity(Gravity.CENTER_HORIZONTAL);
                            value5.setText(servType);
                            value5.setTextColor(Color.parseColor("#1a73b7"));
                            value5.setHeight(60);
                            value5.setGravity(Gravity.CENTER);
                            tableRow5.addView(value5);

....

                            maintable5.addView(tableRow5);
                            addSeparator();

                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            } else if (Api.RESPONSEMSGDATA(response) != null) {
                ConnectionDetector.dialogs(ServiceHistoryActivity.this,
                        "Oops!", Api.RESPONSEMSGDATA(response));
            } else {
                ConnectionDetector.dialogs(ServiceHistoryActivity.this,
                        "Oops!", "Try again later");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            pDialog.hide();
            Toast.makeText(ServiceHistoryActivity.this, String.valueOf(error), Toast.LENGTH_SHORT).show();
        }
    }) {
        @Override
        public Priority getPriority() {
            return Priority.HIGH;
        }
    };
    AppData.getInstance().addToRequestQueue(request);
    request.setShouldCache(false);
Abdur Rahman
  • 894
  • 1
  • 11
  • 27
Muhilan
  • 1
  • 4

1 Answers1

0

You call the API (Volley) from onResume or save the model to restore the data back to Activity

quangminhs
  • 151
  • 5