I need to pass arguments to my fragments but getArguments() alway returns null
public static PersonFragment newInstance(int columnCount, ArrayList<Person> personenListe) {
PersonFragment personFragment = new PersonFragment();
Bundle args = new Bundle();
args.putSerializable("persList",personenListe);
args.putInt(ARG_COLUMN_COUNT, columnCount);
personFragment.setArguments(args);
return new PersonFragment();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) { //getAguments() == null !!
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
mPersonenListe = (ArrayList<Person>) getArguments().getSerializable("persList");
}
}
I'm calling it in MainActivity
openFragment(PersonFragment.newInstance(personenListe.size(), personenListe));
With this method
public void openFragment(Fragment fragment) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
question from:
https://stackoverflow.com/questions/65545655/getarguments-always-returns-null-in-fragment 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…