I have a relative layout and i am adding fragment in that relative layout. Like this
HomeFragment mHomeFragment = new HomeFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction =fragmentManager.beginTransaction();
if(mHomeFragment!=null&& mHomeFragment.isAdded()){
fragmentTransaction.show(mHomeFragment);
}else {
fragmentTransaction.add(R.id.order_container,mHomeFragment,"Search");
}
fragmentTransaction.commit();
I also have a text view where i have to display the name of fragment i added in the relative layout. Like search in case. How to get the name of fragment added in my relative layout suppose with id = R.id.order_container
you can retrieve a Fragment by tag through
then you can check if your fragment is instace of
HomeFragment
If you want to get the tag of a fragment you can use the getTag() method. This probably isn't going to be the nicest way to achieve what you are looking to do.
http://developer.android.com/reference/android/app/Fragment.html#getTag()
If you have several fragments and you will change them around, consider using an adapter.
You can use
findFragmentById
inFragmentManager
You want the name?? You can get your fragment using the ID and doing:
is it what you want? Or you can use:
it's returns the tag name of the fragment, if specified.