创建视图时,不得附加ViewHolder视图。确保您没有将“ true”传递给LayoutInflater.inflate的attachToRoot参数?

时间:2018-09-18 11:24:25

标签: android android-fragments android-recyclerview android-viewholder

我需要一些有关此问题的帮助。突然,我收到此错误。我没有做任何修改,也找不到解决方案……这是一个错误。

  

java.lang.IllegalStateException:创建视图时不得附加ViewHolder视图。确保您未将“ true”传递给   LayoutInflater.inflate(...,boolean的attachToRoot参数   attachToRoot)                   在android.support.v7.widget.RecyclerView $ Adapter.createViewHolder(RecyclerView.java:6687)                   在android.support.v7.widget.RecyclerView $ Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5869)                   在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5752)                   在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5748)                   在com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.layoutDisappearingViews(ChipsLayoutManager.java:767)                   在com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.onLayoutChildren(ChipsLayoutManager.java:731)上                   在android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)                   在android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)                   在android.view.View.measure(View.java:19759)

    package com.example.xandi.amicer;

    import android.support.design.widget.TabLayout;
    import android.support.v4.view.ViewPager;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;

    public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            SectionPagerAdapter mSectionsPagerAdapter = new SectionPagerAdapter(getSupportFragmentManager());

            // Set up the ViewPager with the sections adapter.
            ViewPager mViewPager = findViewById(R.id.container);
            mViewPager.setAdapter(mSectionsPagerAdapter);

            TabLayout tabLayout = findViewById(R.id.tabs);
            tabLayout.setupWithViewPager(mViewPager);

            mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
            tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));

        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_tab_home, menu);
            return true;
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            return super.onOptionsItemSelected(item);
        }

    }
  

我想这是导致此错误的类

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_edit_profile, container, false);

1 个答案:

答案 0 :(得分:-2)

尝试一下:

 @Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
View rootView = inflater.inflate(R.layout.fragment_edit_profile, container, true);
}