Search code examples
androidandroid-fragmentsbundlespannablestring

Can a SpannableString be set in a fragment?


If a SpannableString can be set as the arguments of a fragment how is it done?

        Bundle args = new Bundle();
        args.putString(PagesFragment.ARG_SECTION_NUMBER, Page[position]);
        fragment.setArguments(args);
        return fragment;

What needs to be changed in this sample code?


Solution

  • As SpannableString implements CharSequence you can use putCharSequence method.

        Bundle args = new Bundle();
        args.putCharSequence(PagesFragment.ARG_SECTION_NUMBER, Page[position]);
        fragment.setArguments(args);
        return fragment;
    

    Regards.