0

Можете написать пример передачи массива с одного фрагмента в другой Знаю что так мы отправляем

 Fragment f = new Fragment();
        Bundle bundle = new Bundle();
        bundle.putInt("massive", massive);
        f.setArguments(bundle);

А так принимаю

int massive= getActivity().getIntent().getExtras().getInt("massive");

Но правильно ли я это реализую?

1 ответ 1

3

Нужно вот так отправить:

Bundle bundle = new Bundle();
bundle.putIntArray("array", array);
FragmentClass fragment = new FragmentClass();
fragment.setArguments(bundle);

Вот так получить:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    int array[] = getArguments().getIntArray("array")    
    return inflater.inflate(R.layout.fragment, container, false);
}
3
  • сделал как вы написали,при выводе выводит null
    – fcbarcafc
    10 дек 2017 в 17:14
  • Значит вы что не так делаете, укажите в вопросе в какой момент вы создаете второй фрагмент и в каком месте. 10 дек 2017 в 17:24

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.