Android中的RecyclerView:Java.Lang.IllegalArgumentException:跨度计数应至少为1.提供0

时间:2018-02-13 10:46:52

标签: android adapter

这是一个奇怪的: 在我的应用程序中,我有一个活动,它会使Recyclerview膨胀。这个活动是从我的应用程序中的许多不同活动调用的,具有不同的参数,因此始终相同的recyclerview被夸大,但具有不同的内容。使调整变得非常容易!

无论如何,这就是我启动recyclerview的方式:

var activity2 = new Intent(this, typeof(Activity_RecyclerView));
activity2.PutExtra("galleryType", 0); // 0 neuste, 1 beste
activity2.PutExtra("picturesinarow", 1); // gridbilder
activity2.PutExtra("recyclerLayout", (int)RecyclerLayout.Profile_Singles); // unterschiedliche layouts
activity2.PutExtra("hasHeader", true);
activity2.PutExtra("thumbnails", false);
activity2.PutExtra("RecViewLayout", (int)RecyclerViewLayouts.Profile);
Activity_RecyclerView.gallery = false;
activity2.PutExtra("finalActivity", (int)RecviewHeader.Profile); // What Activity do we want to see?
StartActivity(activity2);

许多意图,导致正确的结果。

现在,在我的recyclerview中,有一个带有按钮的标题。例如,一个按钮重新创建活动,并以3行而不是1行为单位显示recyclerview中的图像。它有点长代码,但看起来就是这样:

internal void RecreateToCorrectActivity(RecReloadPictures sortedBy, int picsInRow, bool hasHeader, RecyclerViewLayouts correctActivity)
{
    // sorted by, pics in row, hasHeader, finalLayout
    switch ((int)sortedBy) // { Newest, Best, HallOfFame, ByTask }
    {
        case 0:
            galleryType = (int)RecReloadPictures.Newest;
            break;
        case 1:
            galleryType = (int)RecReloadPictures.Best;
            break;
        case 2:
            galleryType = (int)RecReloadPictures.HallOfFame;
            break;
        case 3:
            galleryType = (int)RecReloadPictures.ByTask;
            break;
        default:
            galleryType = (int)RecReloadPictures.Newest;
            break;
    }

    if (picsInRow != 1) // sind es mehr als zwei bilder pro reihe, dann thumbnails laden
    {
        thumbnails = true;
        gallery = true;
    }
    else
    {
        thumbnails = false;
        gallery = false;
    }

    switch ((int)correctActivity) // { TheBook, Profile, HOF, StartChallenge }
    {
        case 0:
            finalActivityToLoad = (int)RecviewHeader.TheBook;
            if (picsInRow == 1)
                recyclerLayout = (int)RecyclerLayout.TheBook_Singles;
            else
                recyclerLayout = (int)RecyclerLayout.General_Gallery;
            break;
        case 1:
            finalActivityToLoad = (int)RecviewHeader.Profile;
            if (picsInRow == 1)
                recyclerLayout = (int)RecyclerLayout.Profile_Singles;
            else
                recyclerLayout = (int)RecyclerLayout.General_Gallery;
            break;
        case 2:
            finalActivityToLoad = (int)RecviewHeader.HOF;
            recyclerLayout = (int)RecyclerLayout.HOF_Singles;
            break;
        case 3:
            finalActivityToLoad = (int)RecviewHeader.StartChallenge;
            if (picsInRow == 1)
                recyclerLayout = (int)RecyclerLayout.TheBook_Singles;
            else
                recyclerLayout = (int)RecyclerLayout.General_Gallery;
            break;
        default:
            finalActivityToLoad = (int)RecviewHeader.TheBook;
            if (picsInRow == 1)
                recyclerLayout = (int)RecyclerLayout.TheBook_Singles;
            else
                recyclerLayout = (int)RecyclerLayout.General_Gallery;
            break;
    }

    //ohne prüfung
    this.hasHeader = hasHeader;
    this.picturesinarow = picsInRow; // gridbilder
    boolRecreated = true;
    //this.username = strUsername;
    mAdapter.NotifyDataSetChanged();
    this.Recreate();
}

基本上,我只是重新加载已经打开但具有不同参数的活动。然后我打电话给:

mAdapter.NotifyDataSetChanged();
this.Recreate();

...活动重新加载。只是当加载完成并且recyclerview现在正在膨胀布局时,我得到了上述错误,就是这样。我不知道为什么会发生这种情况。特别是因为在使用所述参数调用时,recyclerview确实有效,当它们来自另一个活动的额外内容时。

任何人都可以帮助我吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

好的,将所有变量更改为静态修复它!