android - Calling a fragment from another fragment on click -
what want call 1 fragment on click on item of listview. program builds without errors crash on click on item. btw i’m making here local fragment_3 object, have got done in mainactivity, how pass function?
fragment_1.java content:
public class fragment_1 extends sherlockfragment implements onitemclicklistener{ @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { super.oncreate(savedinstancestate); // requestwindowfeature(window.feature_no_title); view view = inflater.inflate(r.layout.fragment_1, container, false); listview listview = (listview) view.findviewbyid(r.id.listview1); listview.setonitemclicklistener(this); return view; } @override public void onitemclick(adapterview<?> parent, view v, int position, long id) { // todo auto-generated method stub fragment fragment3 = new fragment_3(); integer fragmentid = (integer) v.gettag(); fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); fragmenttransaction.replace(fragmentid, fragment3); fragmenttransaction.commit(); } }
my suspicion v.gettag()
null; integer fragmentid = (integer) v.gettag();
end in fragmentid being null. when unboxing int you'll nullpointerexception
. why don't replace fragmentid
in fragmenttransaction.replace(fragmentid, fragment3);
id of container holds current instance of fragment_1
?
Comments
Post a Comment