我正在使用TableLayout。 TableRows是从JSON解析中动态添加的。我正在使用Volley方法进行JSON解析。我的问题是当我第一次运行应用程序时创建表行。如果我回到tablelayout活动或重定向到活动,则不会创建表行。
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);
答案 0 :(得分:0)
您从onResume调用API(Volley)或保存模型以将数据恢复回Activity