I am working on Fragment-ListView and having output showing in image. every Click changes TextView of fragment2.till now ok.
fragmetn1 is for listView and fragment2 is for DifferentView.
now i want to change layout in fragment2 with click. e.g. as item2 is clicked,a layout with textView sets in fragment2. now with selection of item3, diferent layout with Button should be set to fragment2.
my getView code is here.
public void onListItemClick(ListView l, View v, int position, long id) {
DetailFrag frag = (DetailFrag) getFragmentManager().findFragmentById(R.id.frag_detail);
if (frag != null && frag.isInLayout()) {
frag.setText("item "+position+" selected");
}
}
is there other way to do this,plz also help that way.
any suggestion would be strongly appreciated.thanks in advance.
Try the following method
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
then you need to add your fragment to this fragmentTransaction with the following syntax.
fragmentTransaction.replace(R.id.detailFragment, layout1);
And finally you MUST commit your transaction. Otherwise changes will not persist.
fragmentTransaction.commit();