The error you are getting is hard to find because your code is all over the place, but the error means you are adding a View
(child) that is allready on the screen (has a parent).
This could be anywhere, hard to say with this post, but for example:
This one probably works:
EditText ed = new EditText(this);
ed.setWidth(250);
lymn.addView(ed);
ed
is new, so doesn't have a parent.
But I can't find the declaration of yes1
, so this one MIGHT be the culprint. Or maybe no1
.
yes1.setText("Yes");
no1.setText("NO");
rg1.addView(yes1);
rg1.addView(no1);
lymn.addView(rg1);
Check all your addView
calls. (hint: there is a line-number in that error somewhere. use it)
To try to answer your question in the comment, you must follow these rules;
- Never add any view more then once.
- When a View is allready used (e.g., you got it with
findViewById
, don't use addView
on it.
- When you want to add a view, use
addView
with a NEW view.
- You can add several of these new views to one view, but you cannot add that one view multiple times.
- You can't re-use a view simply by changing some stuff. You CAN re-use a variable, but you need to make a new view if you want to re-add it using
addView
.
And, I can't stress this more: find out, using the line-number in the error, which line produces the error. Look at what you are adding there, and try to figure out with above help why that doesn't work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…