0

嗨,当片段将一个片段切换到另一个片段时,我会变得昂首阔步..请参阅我的代码帮助我....

MainActivity
-------------------


// adding new item

addItem()
{
FragmentManager mFragmentManger = getFragmentManager();

FragmentTransaction transaction = mFragmentManager.beginTransaction();
transaction.remove(mFragmentManager.findFragmentByTag(Constants.TAG_LIST));

Fragment fragmentAdd = new AddFragment(mFragmentManager);

transaction.add(R.id.ListLayout, fragmentAdd,"AddNew").addToBackStack()
                .commit();
}

// Detailsfragment listItem 

editItem()
{
transaction.remove(mFragmentManager.findFragmentByTag(Constants.TAG_LIST));

Fragment editFragment = new Detailsfragment(mFragmentManager);

transaction.add(R.id.ListLayout, Detailsfragment).addToBackStack(null).commit();


}





AddFragment
---------------------

nextButton()
{
CoformFragment confrom = new CoformFragment();

transaction.remove(mFragmentManager.findFragmentByTag("AddNew"));
transaction.add(R.id.ListLayout, fragment,"coform").addToBackStack(null).commit();

}


CancelButton()
{
mFragmentManeger.popBackStack();

}



CoformFragment
----------------------

conformButton()
{
transaction.remove(mFragmentManager.findFragmentByTag("Number"));
Fragment listFragmrnt = mFragmentManager.findFragmentByTag(Constants.TAG_LIST);

transaction.replace(R.id.ListLayout, listFragment).commit();

}

backButton()
{
mFragmentManeger.popBackStack();

}




Detailsfragment
------------------

showListDetails()
{
mFragmentManager.beginTransaction().replace(R.id.listLayout, fragment).commit();

}



EditFragment
-------------------

confromButton()
{

updated values

then

Detailsfragment fragment = new Detailsfragment();

mFragmentManager.beginTransaction().replace(R.id.listLayout, fragment).commit();

}

cancelButton()
{

mFragmentManager.beginTransaction().replace(R.id.listLayout, fragment).commit();
}

第一次然后第二次重叠时它工作正常

main-->add->>confrom-->main

main-->details-->edit-->main

第一次工作正常,当我在第二次添加或编辑时,我将用 add 和 main 与 deatil 片段重叠

如何解决这个问题

4

0 回答 0