Fragment won't launch

后端 未结 2 898
感动是毒
感动是毒 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:25

    change this line

    Intent intent =new Intent(eventList.this, fr.getClass());
    

    to:

    fragmentTransaction.commit;
    

    and better replace fragment in container ,

    fragmentTransaction.replace(R.id.page, fr);
    
    0 讨论(0)
  • 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();
    }
    
    0 讨论(0)
提交回复
热议问题