IllegalStateException: не может выполнить это действие после onSaveInstanceState с ViewPager

Я делаю это так:

function isString(value)
{
    return value.length !== undefined;
}
function isNumber(value)
{
    return value.NaN !== undefined;
}

Конечно, isString () будет сработано здесь, если вы передадите другой объект, у которого определена длина.

447
задан Chandrani Chatterjee 14 February 2019 в 11:08
поделиться

1 ответ

расширение Kotlin

fun FragmentManager?.replaceAndAddToBackStack(
    @IdRes containerViewId: Int,
    fragment: () -> Fragment,
    tag: String
) {
    // Find and synchronously remove a fragment with the same tag.
    this?.findFragmentByTag(tag)?.let {
        beginTransaction().remove(it).commitNow()
    }
    // Add a fragment.
    this?.beginTransaction()?.run {
        replace(containerViewId, fragment, tag)
        // The next line will add the fragment to a back stack.
        // Remove if not needed.
        addToBackStack(null)
    }?.commitAllowingStateLoss()
}

Использование:

val fragment = { SomeFragment.newInstance(data) }
fragmentManager?.replaceAndAddToBackStack(R.id.container, fragment, SomeFragment.TAG)
0
ответ дан CoolMind 28 July 2019 в 18:35
поделиться
Другие вопросы по тегам:

Похожие вопросы: