I am creating a tablet application. In this application, there is one action with two fragments. The first fragment is a โknownโ fragment of the list, which shows a simple list of layouts of elements from the database query, the second fragment shows the details of the selected record (from the list fragment). The thought with the second fragment is that its type depends on the entries displayed in the list. For example, if the records are customers, then the selected customer data is displayed, if they are inventory items, the data of the selected item is displayed, etc. To contact the fragment of parts, I created an interface that implements each fragment of the fragment. A fragment of the list is "fixed" in the activity from the xml layout. However, a part fragment is created during activity creation as follows:
super.onCreate(savedInstanceState); setContentView(R.layout.act_hlpfiles_host); ..... FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.laydetailsfragment, FragmentsPool.getHelperFileFragment(501), "recordDetails"); fragmentTransaction.commit(); myDetailsFragment = getFragmentManager().findFragmentByTag("recordDetails"); ... myListFragment = (frg_hlpfiles_lstrecords) getFragmentManager().findFragmentById(R.id.frg_lstrecords); .... }
The problem with this code is that myDetailsFragment is always null. This is because the Transaction.commit () fragment does not start immediately, but it happens in the main thread the next time the thread is ready (as indicated in the android documentation).
If I create a part fragment in onStart () and instantiate a list fragment in onCreate, everything works fine.
So the question is: how can I be sure that the Transaction.commit () fragment completed the transaction so that I can do some work with the added fragment? Also, is there a way to wait for the commit to happen and then continue with the rest of the code?
Thank you for your time and efforts,
Christ
android android-fragments
Christos Aug 30 '11 at 16:24 2011-08-30 16:24
source share