gpt4 book ai didi

android - BaseExpandableListAdapter 指定的child已经有一个parent

转载 作者:行者123 更新时间:2023-11-30 03:23:49 25 4
gpt4 key购买 nike

你好,我有这个代码:

public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
ExpandListChild child = (ExpandListChild) getChild(groupPosition,
childPosition);
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.expandlist_child_item, null);
}

TextView tv = (TextView) view.findViewById(R.id.child);
if(child.getName() != null)
tv.setText(child.getName().toString());

LinearLayout image = (LinearLayout) view.findViewById(R.id.instructionsHelper);

RelativeLayout layouts = child.getLayouts();

if(layouts != null)
{
image.removeAllViews();
image.addView(layouts);
}

return view;
}

我在这一行收到错误:

image.addView(layouts);

我不明白为什么会出现此错误,因为我调用了 image.removeAllViews();

我的日志:

09-04 14:33:34.366: E/AndroidRuntime(8585): FATAL EXCEPTION: main
09-04 14:33:34.366: E/AndroidRuntime(8585): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.addView(ViewGroup.java:3210)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.addView(ViewGroup.java:3155)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.addView(ViewGroup.java:3131)
09-04 14:33:34.366: E/AndroidRuntime(8585): at com.example.workoutlog.ExpandListAdapter.getChildView(ExpandListAdapter.java:71)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.widget.ExpandableListConnector.getView(ExpandableListConnector.java:469)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.widget.ListAdapterWrapper.getView(ListAdapterWrapper.java:83)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.AbsListView.obtainView(AbsListView.java:2143)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.ListView.measureHeightOfChildren(ListView.java:1246)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.ListView.onMeasure(ListView.java:1158)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:666)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.widget.LinearLayout.forceUniformWidth(LinearLayout.java:286)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.widget.LinearLayout.measureVertical(LinearLayout.java:1065)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.widget.LinearLayout.onMeasure(LinearLayout.java:1105)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at org.holoeverywhere.internal.WindowDecorView.onMeasure(WindowDecorView.java:114)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
09-04 14:33:34.366: E/AndroidRuntime(8585): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2434)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.View.measure(View.java:15525)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.Choreographer.doFrame(Choreographer.java:532)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.os.Handler.handleCallback(Handler.java:725)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.os.Handler.dispatchMessage(Handler.java:92)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.os.Looper.loop(Looper.java:137)
09-04 14:33:34.366: E/AndroidRuntime(8585): at android.app.ActivityThread.main(ActivityThread.java:5226)
09-04 14:33:34.366: E/AndroidRuntime(8585): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 14:33:34.366: E/AndroidRuntime(8585): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 14:33:34.366: E/AndroidRuntime(8585): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-04 14:33:34.366: E/AndroidRuntime(8585): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-04 14:33:34.366: E/AndroidRuntime(8585): at dalvik.system.NativeStart.main(Native Method)

最佳答案

看这里

java.lang.IllegalStateException: 指定的子项已有父项。您必须先对 child 的 parent 调用 removeView()。

所以首先你应该 layout.removeView(layouts)

然后您将layouts 分配给任何其他父级。因为你不能同时给两个 parent 分配一些东西。

关于android - BaseExpandableListAdapter 指定的child已经有一个parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18612799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com