OK so i finally found a simple way to solve the question.. I had to pass the parent view through the contructor.. I think the code will explain this better..
From the ProfessorFragment which contains the listview, which in turn uses the custom adater, i get a reference to the parent view and the pass it into adapter's contructor
new android.os.Handler().post(new Runnable() {
@Override
public void run() {
cursor = dataSource.getAllProfessors();
/*Get parent view*/
parent_view = ((ViewGroup) getView().getParent());
adapter = new ProfessorCardAdapter(getActivity(), cursor, true, parent_view);
professors_listview.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
});
Then in my cursor adapter i get the parent view like this
public ProfessorCardAdapter(Context context, Cursor c, boolean autoRequery, ViewGroup p_view) {
super(context, c, autoRequery);
appContext = context;
dataSource = new ProfessorDataSource(context);
frag_context = (FragmentActivity) context;
parent_view = p_view;
this.c = c;
}
Now with this parent view i can call the new fragment without messing up the view hierarchy
FragmentManager fm = frag_context.getSupportFragmentManager();
UpdateProfessorFragment frag = new UpdateProfessorFragment();
FragmentTransaction transaction = fm.beginTransaction();
transaction.replace(parent_view.getId() , frag).addToBackStack(null).commit();
This worked fine for me.. thank you all for the support :)