gpt4 book ai didi

android - 布局状态应该是 100 之一,但它是 10

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:13 31 4
gpt4 key购买 nike

<分区>

我正在尝试膨胀并将我的数据绑定(bind)到我的 ViewHolder。每当我绑定(bind)时我都会遇到这个错误:

java.lang.IllegalStateException: Layout state should be one of 100 but it is 10
at android.support.v7.widget.RecyclerView$State.assertLayoutStep(RecyclerView.java:10876)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3391)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3194)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3627)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1799)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1367)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:849)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13916)
at android.view.ViewGroup.layout(ViewGroup.java:4424)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2029)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1850)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1143)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4667)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)

我以前从未遇到过这个错误。关于此的信息也不多。发生这种情况的任何原因?

编辑

我认为问题出在这段代码上:

public class ProfileAdapter extends RecyclerView.Adapter<TypedHolder>
{
public static final int TYPE_HEADER = 0;
public static final int TYPE_MAP = 1;

private List<GeoMap> mGeoMaps = new ArrayList<>();
private Context mContext;
private User mCurrentUser;

private ProfileHeaderHolderInterface mProfileHeaderHolder;
private DownloadedMapHolderInterface mDownloadedMapHolder;

private ProfileHeaderHolderInterface.Listener mProfileHeaderHolderInterfaceListener;
private DownloadedMapHolderInterface.Listener mDownloadedMapHolderInterfaceListener;

private ProfileHeaderHolderInterface.OnBind mProfileHeaderHolderInterfaceOnBind;
private DownloadedMapHolderInterface.OnBind mDownloadedMapHolderInterfaceOnBind;


public ProfileAdapter(Context context)
{
mContext = context;

mProfileHeaderHolder = new ProfileHeaderHolder(mContext);
mDownloadedMapHolder = new DownloadedMapHolder(mContext);
}

public void setContent(List<GeoMap> map, User user)
{
if(map == null)
return;

mGeoMaps.clear();
mGeoMaps.addAll(map);

mCurrentUser = user;
}

public ProfileHeaderHolderInterface getProfileHeaderView()
{
return mProfileHeaderHolder;
}

@Override
public TypedHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.from(mContext);

switch(viewType)
{
case TYPE_HEADER:
return mProfileHeaderHolder.createHolder(parent);
case TYPE_MAP:
{
View view = inflater.inflate(R.layout.listitem_offline_map, parent, false);
DownloadedMapHolder.ViewHolder holder = new DownloadedMapHolder.ViewHolder(view);
// return mDownloadedMapHolder.createHolder(parent);
return holder;
}
}

return new TypedHolder(new View(mContext), -1);
}

@Override
public int getItemViewType(int position)
{
if(position == 0)
return TYPE_HEADER;

return TYPE_MAP;
}

@Override
public void onBindViewHolder(TypedHolder holder, int position)
{
switch(holder.getType())
{
case ProfileAdapter.TYPE_HEADER:
if(mProfileHeaderHolderInterfaceListener != null)
mProfileHeaderHolderInterfaceOnBind.onBind(holder, mCurrentUser);
break;

case ProfileAdapter.TYPE_MAP:
{
GeoMap geoMap = mGeoMaps.isEmpty()? null : mGeoMaps.get(position - 1);

//if (mDownloadedMapHolderInterfaceListener != null)
// mDownloadedMapHolderInterfaceOnBind.onBind(holder, geoMap, position - 1);

DownloadedMapHolder.ViewHolder downloadedMapHolder = (DownloadedMapHolder.ViewHolder) holder;
downloadedMapHolder.mTextViewLocation.setText(geoMap.getMapLocation());
downloadedMapHolder.mTextViewLocation.setText(geoMap.getDateString());
}
break;
}
}

@Override
public int getItemCount()
{
return mGeoMaps.isEmpty()? 1 : mGeoMaps.size() + 1;
}

public void setProfileHeaderHolderInterfaceListener(ProfileHeaderHolderInterface.Listener listener)
{
mProfileHeaderHolderInterfaceListener = listener;
mProfileHeaderHolder.setProfileHeaderHolderInterfaceListener(listener);
}

public void setDownloadedMapHolderInterfaceListener(DownloadedMapHolderInterface.Listener listener)
{
mDownloadedMapHolderInterfaceListener = listener;
mDownloadedMapHolder.setDownloadedMapHolderInterfaceListener(listener);
}

public void setProfileHeaderHolderInterfaceOnBind(ProfileHeaderHolderInterface.OnBind onBind)
{
mProfileHeaderHolderInterfaceOnBind = onBind;
}

public void setDownloadedMapHolderInterfaceOnBind(DownloadedMapHolderInterface.OnBind onBind)
{
mDownloadedMapHolderInterfaceOnBind = onBind;
}
}

这个问题非常令人沮丧。在我只用一些必需品剥离我的适配器后,我能够弄清楚它是在这条线上出现的:

@Override
public int getItemViewType(int position)
{
if(position == 0)
return TYPE_HEADER;

else if(position > 0 && position < mGeoMaps.size())
return TYPE_MAP;
else
{
Log.i(ShoreLeaveApplication.TAG, "CANNOT BIND on TYPE -1!!!!");
return -1;
}
}

我试图创建一个非常简单的回收器 View ,其中有一个添加记事卡始终作为我列表的顶部和第一个元素(类似于 FB)。剩下的只是 map 选择。这会导致我的 onCreateViewHolder 收到无效的 id 并膨胀错误的布局。当它到达最后一项时会发生这种情况。这是我匆忙写的蹩脚代码并用这个替换它:

@Override
public int getItemViewType(int position)
{
if(position == 0) // first item is always the header
return TYPE_HEADER;

// the rest is a normal item
return TYPE_MAP;
}

现在可以了。

谢谢!

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