android - At what point does the fragment in a container change after i call the commit method? -
i trying edit data in fragment activity. have called fragment manager replace fragment in container new fragment, when try cast fragment in container new type, error:
java.lang.classcastexception: com.mycompany.myapp.fragment2 cannot cast com.mycompany.myapp.fragment1.
here code in activity
public void respond(transaction.type type, string title, double amount, string description) { add_edit_transaction fragment = new add_edit_transaction(); fm.begintransaction().replace(r.id.maincontent,fragment).commit(); toast.maketext(this, "replaced!", toast.length_short).show(); add_edit_transaction frag= (add_edit_transaction)fm.findfragmentbyid(r.id.maincontent); }
the commit not happen immediately; scheduled work on main thread done next time thread ready.
if need transaction happen can force calling fragmentmanager.executependingtransactions()
Comments
Post a Comment