Fragment to Fragment Interface error (layout)

后端 未结 1 714
独厮守ぢ
独厮守ぢ 2021-01-26 09:33

I\'m sending an interface from Fragment 5 to 3 through the main activity :

public void setF3Riddle(int x) {

  Frag3 F3 = (Frag3) getSupportFragmentManager().fin         


        
相关标签:
1条回答
  • 2021-01-26 10:01

    The problem probably is from here:

    Frag3 frag = new Frag3();
    Bundle args = new Bundle();
    args.putInt("Value", x);
    frag.setArguments(args);
    getSupportFragmentManager().beginTransaction()
                               .replace(R.id.Frag3, frag)
                               .addToBackStack(null)
                               .commit();
    frag.getF3Riddle(x);
    

    You're creating the fragment with Frag3 frag = new Frag3(); and put the bundle then you want to get the value with frag.getF3Riddle(x). But it will throw an error because the the fragment is not yet finished created. Fragment creation is asynchronous process. So, you need to wait until the frag is finished created or create it in another place first.

    0 讨论(0)
提交回复
热议问题