Fragment won't launch

后端 未结 2 921
感动是毒
感动是毒 2021-01-29 02:03

I have onclicklistener that works. I am trying to launch a new fragment from the button click on the list view. Right now, the fragment does not launch. However, the emulator we

2条回答
  •  甜味超标
    2021-01-29 02:30

    You should be using commit() to start your transaction, not an Intent(), you also want to use replace() not add():

     public void onItemClick(AdapterView adapterView, View view, final int i, long l)
    {
        //Assuming that this creates a new fragment
        Fragment fr = new event_description();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.replace(R.id.page, fr, "TAG ID");
        fragmentTransaction.commit();
    }
    

提交回复
热议问题