0
나는 서버로부터 정보를 가져오고 그것을 표 형식으로 표시하려고하므로 json 객체를 사용하려고한다."지정된 자식에는 이미 부모가 있습니다. 먼저 자식의 부모에서 removeView()를 호출해야합니다." android에서의 예외
코드 :!
JSONArray jsonArray = new JSONArray(jsonResult);
TableLayout tv=(TableLayout) findViewById(R.id.table);
tv.removeAllViewsInLayout();
int flag=1;
for (int i = 0; i < jsonArray.length() ; i++) {
//JSONObject object1 = jsonArray.getJSONObject(i);
TableRow tr=new TableRow(viewtimetable.this);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
if(flag==1)
{
TextView col1=new TextView(viewtimetable.this);
col1.setText("Day");
col1.setTextColor(Color.BLUE);
col1.setTextSize(15);
tr.addView(col1);
TextView col2=new TextView(viewtimetable.this);
col2.setPadding(10, 0, 0, 0);
col2.setTextSize(15);
col2.setText("7:30-9:10AM");
col2.setTextColor(Color.BLUE);
tr.addView(col2);
TextView col3=new TextView(viewtimetable.this);
col3.setPadding(10, 0, 0, 0);
col3.setText("9:20-11:00AM");
col3.setTextColor(Color.BLUE);
col3.setTextSize(15);
tr.addView(col3);
TextView col4=new TextView(viewtimetable.this);
col4.setPadding(10, 0, 0, 0);
col4.setText("11:10-12:50PM");
col4.setTextColor(Color.BLUE);
col4.setTextSize(15);
tr.addView(col4);
TextView col5=new TextView(viewtimetable.this);
col5.setPadding(10, 0, 0, 0);
col5.setText("1:40-3:20PM");
col5.setTextColor(Color.BLUE);
col5.setTextSize(15);
tr.addView(col5);
TextView col6=new TextView(viewtimetable.this);
col6.setPadding(10, 0, 0, 0);
col6.setText("3:30-5:00PM");
col6.setTextColor(Color.BLUE);
col6.setTextSize(15);
tr.addView(col6);
tv.addView(tr);
final View vline = new View(viewtimetable.this);
vline.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
vline.setBackgroundColor(Color.BLUE);
tv.addView(vline);
flag=0;
}
else
{
try{
JSONObject json_data = jsonArray.getJSONObject(i);
//Log.i("log_tag","id: "+json_data.getInt("f1")+
// ", Username: "+json_data.getString("f2")+
// ", No: "+json_data.getInt("f3"));
//((ViewGroup)tr.getParent()).removeView(tr);
TextView b=new TextView(viewtimetable.this);
String stime=json_data.getString("day");
b.setText(stime);
b.setTextColor(Color.RED);
b.setTextSize(15);
tr.addView(b);
TextView b1=new TextView(viewtimetable.this);
b1.setPadding(10, 0, 0, 0);
b1.setTextSize(15);
if(json_data.getString("slot").equals("7:30-9:10AM")){
String stime1=json_data.getString("subject");
b1.setText(stime1);
}
b1.setTextColor(Color.WHITE);
tr.addView(b1);
TextView b2=new TextView(viewtimetable.this);
b2.setPadding(10, 0, 0, 0);
if(json_data.getString("slot").equals("9:20-11:00AM")){
String stime2=json_data.getString("subject");
b2.setText(stime2);
}
b2.setTextColor(Color.RED);
b2.setTextSize(15);
tr.addView(b2);
TextView b3=new TextView(viewtimetable.this);
b3.setPadding(10, 0, 0, 0);
if(json_data.getString("slot").equals("11:10-12:50PM")){
String stime3=json_data.getString("subject");
b3.setText(stime3);
}
b3.setTextColor(Color.RED);
b3.setTextSize(15);
tr.addView(b2);
TextView b4=new TextView(viewtimetable.this);
b4.setPadding(10, 0, 0, 0);
if(json_data.getString("slot").equals("1:40-3:20PM")){
String stime4=json_data.getString("subject");
b4.setText(stime4);
}
b4.setTextColor(Color.RED);
b4.setTextSize(15);
tr.addView(b2);
TextView b5=new TextView(viewtimetable.this);
b5.setPadding(10, 0, 0, 0);
if(json_data.getString("slot").equals("3:30-5:00PM")){
String stime5=json_data.getString("subject");
b5.setText(stime5);
}
b5.setTextColor(Color.RED);
b5.setTextSize(15);
tr.addView(b2);
tv.addView(tr);
}catch(JSONException e){
content.setText("jsonexception");
}
final View vline1 = new View(viewtimetable.this);
vline1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
vline1.setBackgroundColor(Color.WHITE);
tv.addView(vline1);
}
내가 here을 볼 수있는 솔루션을 찾고 후하지만이 부르게 예외 인 아이에 대해 점점 아니에요 사용하는 위치를 모르는 그것은 일 것 당신이 이것을 설명 할 수 있다면 큰 도움이됩니다.
질문 : 위의 링크에서 다음 줄이 내 문제의 해결책이라는 것을 알고 있습니다.
((ViewGroup)scrollChildLayout.getParent()).removeView(scrollChildLayout);
제 경우에는 어디에서 어떻게 사용합니까?
내 바보 같은 바보 같은 실수를 고맙게 생각해 주셔서 감사합니다. 또한 제안을 주셔서 감사합니다. –