중첩 된 TableLayout
이있는 LinearLayout에 대한 질문이 있습니다. TableLayout
은 ImageViews로 동적으로 채워진 행 col로 채워집니다. 기능보기 addImagesToTableLayout()
LinearLayout에 TableLayout을 동적으로 추가하고 LinearLayout에서 TableLayout을 제거한 다음 다시로드하십시오.
실제로 응용 프로그램을 시작할 때 모든 것이 작동합니다. LinearLayout은 ImageViews로 중첩 된 중첩 된 TableLayout으로로드됩니다. 이미지 중 하나를 클릭하면 부모의 이미지가 모두 TableLayout
인 TableLayout by its self
을 완전히 제거해야합니다. 그래서 난 내 LinearLayout
제거에 새로운 신선한 TableLayout
을 추가 할 수 있습니다하는 것은 문제가되지 않습니다, 문제는 내가 addImagesToTableLayout를 호출 할 때()이다;
java.lang.IllegalStateException: The specified child already has a parent. You must
call removeView() on the child's parent first.
private void addImagesToTableLayout(ArrayList<ImageView> imageViewCollection){
tablelayout = new TableLayout(this);
LayoutParams param = new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
param.weight = 2.0f;
param.gravity = Gravity.CENTER;
param.leftMargin = portraitmargin - (sqr) ;
tablelayout.setLayoutParams(param);
tableRows = new TableRow[levelNumber-1];
int m = 0;//modulo
int i = 0;
int f = 0;
for (ImageView s : imageViewCollection)
{
m = (i) % sqr;
if (m == 0){
tableRows[f] = new TableRow(this);
tableRows[f].setId(f+1);
f++;
}
tableRows[f-1].addView(imageViewCollection.get(i));
i++;
}
for(int j = 0; j < sqr; j++) {
tableRows[j].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
tableRows[j].setWeightSum(1.0f);
tablelayout.addView(tableRows[j]);
}
linearlayout.addView(tablelayout);
}
// remove tablelayout
linearlayout.removeAllViews();
if(linearlayout.getChildCount() == 0) {
// add a new TableLayout to my root linearLayout (gives error see above)
addImagesToTableLayout(imageViewCollection);
}
내가 당신의 제목에 아무 상관이 간단하기 때문에, 당신에게 내려 줄 것이라고 :
은 또한 OnClickListener를의 방법 안에, 당신은 당신의 물건이 table.This를 형성 제거하는 코드 줄을 추가해야 질문으로 대답하십시오 ... 제목의 질문에 답하기 위해 3-4 분을 허리를 훑어보고 코드를 한 번 보아서 LinearLayout에 tableLayout을 추가하는 방법을 실제로 알고 있는지 확인하십시오. "귀하의 제목에 ... 귀하의 질문에 적절한 제목을 게시하는 방법을 배웁니다. – Vlad
죄송합니다 블라드 맞습니다.하지만 잘 읽으면 더 명확하게 생각합니다. 어쨌든 나는 제목을 바꿉니다. –
예, 당신도 맞습니다. 나는 당신의 코드에서 외면적으로 보였습니다. ... 어쨌든, 저는 생각합니다. 희망대로 질문에 대답했습니다. 자세한 내용이 필요하면 의견을 통해 알려주십시오. – Vlad