Piy*_*ush 14 android view radio-button
我的代码在这里
if(c!=null)
{
c.moveToFirst();
String col = c.getString(2); //
check.setText(col);
check.setVisibility(0);
while(!c.isAfterLast())
{
String col1 = c.getString(1);
String col2 = c.getString(2);
String col3 = c.getString(3);
while(!c.isAfterLast())
{
TextView que1 = new TextView(this);
que1.setText(col1);
lymn.addView(que1);
if(col3.equals("Date"))
{
DatePicker dp = new DatePicker(this);
lymn.addView(dp);
break;
}
if(col3.equals("User Input"))
{
EditText ed = new EditText(this);
ed.setWidth(250);
lymn.addView(ed);
break;
}
if(col3.equals("YES/NO"))
{
yes1.setText("Yes");
no1.setText("NO");
rg1.addView(yes1);
rg1.addView(no1);
lymn.addView(rg1);
break;
}
if(col3.equals("High Average Low"))
{
High1.setText("High");
Avg1.setText("Average");
Low1.setText("Low");
rg2.addView(High1);
rg2.addView(Avg1);
rg2.addView(Low1);
lymn.addView(rg2);
break;
}
if(col3.equals("Excellent Good Average Poor"))
{
exce1.setText("Excellent");
good1.setText("Good");
avg11.setText("Average");
poor1.setText("Poor");
rg3.addView(exce1);
rg3.addView(good1);
rg3.addView(avg11);
rg3.addView(poor1);
lymn.addView(rg3);
break;
}
break;
}
c.moveToNext();
}
}
Run Code Online (Sandbox Code Playgroud)
当我像这样运行此代码igot错误
09-06 11:34:37.777: WARN/Exception(27814): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1865)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1822)
09-06 11:34:37.777: WARN/Exception(27814): at android.view.ViewGroup.addView(ViewGroup.java:1802)
09-06 11:34:37.777: WARN/Exception(27814): at com.ezee.app.user1.LoadCheckIn(user1.java:256)
09-06 11:34:37.777: WARN/Exception(27814): at com.ezee.app.user1.onCreate(user1.java:61)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-06 11:34:37.777: WARN/Exception(27814): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 11:34:37.777: WARN/Exception(27814): at android.os.Looper.loop(Looper.java:123)
09-06 11:34:37.777: WARN/Exception(27814): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-06 11:34:37.777: WARN/Exception(27814): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 11:34:37.777: WARN/Exception(27814): at java.lang.reflect.Method.invoke(Method.java:521)
09-06 11:34:37.777: WARN/Exception(27814): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-06 11:34:37.777: WARN/Exception(27814): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-06 11:34:37.777: WARN/Exception(27814): at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题
Nan*_*nne 41
您得到的错误很难找到,因为您的代码遍布整个地方,但错误意味着您正在添加一个View
已经在屏幕上的(子)(具有父级).
这可能是任何地方,很难说这篇文章,但例如:
这可能有效:
EditText ed = new EditText(this);
ed.setWidth(250);
lymn.addView(ed);
Run Code Online (Sandbox Code Playgroud)
ed
是新的,所以没有父母.
但是我找不到声明yes1
,所以这一个可能是罪魁祸首.或者也许吧no1
.
yes1.setText("Yes");
no1.setText("NO");
rg1.addView(yes1);
rg1.addView(no1);
lymn.addView(rg1);
Run Code Online (Sandbox Code Playgroud)
检查所有addView
通话.(提示:某处出现该错误的行号.使用它)
要在评论中回答您的问题,您必须遵守这些规则;
findViewById
,不要使用addView
它.addView
新视图.addView
.并且,我不能再强调这一点:使用错误中的行号找出,哪一行产生错误.看看你在那里添加什么,并试着找出上面的帮助,为什么这不起作用.
归档时间: |
|
查看次数: |
43397 次 |
最近记录: |