I am developing an app which has navigation drawer which calls RecyclerView.Adapter. RecyclerView.Adapter has list of schedules. I have footer in RecyclerView which enabled user to create new schedule.
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
protected void onCreate(Bundle savedInstanceState) {
…
}
public void selectItemDrawer(MenuItem menuItem){
Fragment myFragment = null;
Class fragmentClass;
switch (menuItem.getItemId()) {
case R.id.menu_home:
fragmentClass = dashboardFragment.class;
break;
case R.id.menu_plans:
fragmentClass = ScheduleListFragment.class;
break;
default:
fragmentClass = dashboardFragment.class;
}
try {
myFragment = (Fragment) fragmentClass.newInstance();
}
catch (Exception e) {
e.printStackTrace();
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent,myFragment).commit();
menuItem.setCheckable(true);
setTitle(menuItem.getTitle());
mDrawerLayout.closeDrawers();
}
}
Adapter Class
public class MyRecyclerAdapter extends Adapter<RecyclerAdapter.ViewHolder> {
private ArrayList<ScheduleModel> activeSchedules;
private ShowScheduleListener mListener;
public MyRecyclerAdapter(Context ctx, ShowScheduleListener listener){
mListener = listener;
...
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.itemView.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
mListener.onItemClicked(mItems[position]);
}
});
}
interface ShowScheduleListener{
void onItemClicked(ItemType item);
}
}
}
RecyclerView Fragment
public class ScheduleList extends Fragment implements MyRecyclerAdapter.ShowScheduleListener {
View v;
private RecyclerView scheduleRecyclerView;
private ArrayList<ScheduleModel> activeSchedules;
private DatabaseHandler databaseHandler;
public ScheduleList() {
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_schedule_list,container,false);
scheduleRecyclerView=v.findViewById(R.id.RecyclerView_schedule_list);
scheduleRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
activeSchedules = new ArrayList<>();
databaseHandler=DatabaseHandler.getInstance(getContext());
activeSchedules=databaseHandler.getActiveSchedules();
return v;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MyRecyclerAdapter myRecyclerAdapter = new MyRecyclerAdapter (getContext(), activeSchedules);
scheduleRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
scheduleRecyclerView.setAdapter(myRecyclerAdapter);
}
#Override
public void onScheduleItemClick(int position) {
// as per other posts I am supposed to initiate Fragment here
// but should fragment talk to another fragment via interface implemented this way?
}
I have 2 questions
Is it a good architecture to implement Navigation drawer -> Fragment to show existing schedules with RecycleView -> Fragment to show selected schedule details?
How to pass information to fragment from RecycleView?. I know communication between fragment could be achieved using interface but wanted to check if there is any other way to implement communication between RecycleView and Fragment?
Is it a good architecture to implement Navigation drawer -> Fragment to show existing schedules with RecycleView -> Fragment to show selected schedule details?
That is how the default calendar app on android works. So, yes, that's a good architecture. The default calendar app has a nav drawer. Clicking the drawer's "Schedule" item opens up the Schedule fragment with a list of events. Clicking on one of the events opens up the detail screen for that particular event.
How to pass information to fragment from RecycleView?. I know communication between fragment could be achieved using interface but wanted to check if there is any other way to implement communication between RecycleView and Fragment?
Use bundles: How to transfer some data to another Fragment?
Related
I have a tablayout (with 3 tabs) with viewpager and fragments.
I m trying to send the parsed Json data from MainActivity( When searchview data submitted ) to show in the textview of tabs fragments
See this Image link
The data is succesfully parsing but textview with data(in first tab) is not showing unless scrolled to 3rd tab
//Passing data from MainActivity
public String getMyData() {
return meaning;
}
//Setting value to textview from Fragment
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v=inflater.inflate(R.layout.fragment_meaning, container, false);
MainActivity mainActivity= (MainActivity) getActivity();
assert mainActivity != null;
String data= mainActivity.getMyData();
TextView textView=v.findViewById(R.id.textVIew);
textView.setText(data);
return v;
}
Want to able to show data changes instantly as it is parsed, instead of scrolling to 3rd tab to see changes
Here are some steps that might help you.
On the ViewPager adaptor you have created, make the fragment objects. like below
FragmentOne fragOne; // this should be global
On the viewPager adaptor, do some thing like this,
fragOne = new FragmentOne() // whatever your implementation is.
Then after fetching the data from the server,
if ( fragOne != null ) {
fragOne.setValueOnView( " your data to be passed" );
}
and on the FragmentOne, create a function called setValueOnView
void setValueOnView(String yourString) {
v.findViewById(R.id.textVIew).setText(yourString);
}
And one more thing, while initializing the fragment onCreateView, create an object of View
View v; // global variable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v=inflater.inflate(R.layout.fragment_meaning, container, false);
Use this approach for other fragments as well
Inside getItem() method in ViewPager class use Fragment constructors with String parameter
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
FragmentOne tab1 = new FragmentOne("string parameter");
return tab1;
case 1:
FragmentTwo tab2 = new FragmentTwo("string parameter");
return tab2;
case 2:
FragmentThree tab3 = new FragmentThree("string parameter");
return tab3;
default:
return null;
}
}
Inside your Fragment:
public FragmentOne(String stringParameter) {
yourLocalVariable = stringParameter; // yourLocalVariable is declared inside Fragment class;
//now you can setText() for your TextView inside onViewCreated()
}
Of course you pass your String from MainActivity to ViewPager like you did earlier.
Use Observer
public class FragmentObserver extends Observable {
#Override
public void notifyObservers() {
setChanged(); // Set the changed flag to true, otherwise observers won't be notified.
super.notifyObservers();
}
}
Activity:
public class MyActivity extends Activity {
private MyAdapter mPagerAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.my_activity);
ViewPager pager = (ViewPager) findViewById(R.id.pager);
mPagerAdapter = new MyAdapter();
pager.setAdapter(mPagerAdapter);
}
private void updateFragments() {
mPagerAdapter.updateFragments();
}
}
Viewpager adapter
public class MyAdapter extends FragmentPagerAdapter {
private Observable mObservers = new FragmentObserver();
public MyAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
mObservers.deleteObservers(); // Clear existing observers.
Fragment fragment = new MyFragment();
if(fragment instanceof Observer)
mObservers.addObserver((Observer) fragment);
return fragment;
}
public void updateFragments() {
mObservers.notifyObservers();
}
}
Your Fragment
public class MyFragment extends Fragment implements Observer {
/* Fragment related stuff... */
#Override
public void update(Observable observable, Object data) {
View root = getView();
// Update your views here.
}
}
You will get data to update method even your fragment already loaded
I created three tabs with three fragments using view pager.I want to jump to inspiring fragment after clicking on list item defined inside Categories Fragment(Tab Fragment created with view pager).When i click on the list item error occurs.I want to jump to inspiring fragment from categories fragment(fragment defined inside view pager).
Categories (Tab Fragment created with view pager)
public class Categories extends Fragment {
private RecyclerView recyclerView;
private List<CategoriesDataModel> list;
private String[] categories={"Inspiring","Feelings","Strength","Hard Work","Success"};
public Categories() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_categories, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.categoriesList_Id);
list = new ArrayList<>();
for (int i = 0; i < categories.length; i++) {
CategoriesDataModel dataModel = new CategoriesDataModel();
dataModel.cat_name = categories[i];
list.add(dataModel);
}
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setHasFixedSize(true);
CategoryRecyclerViewAdapter adapter = new CategoryRecyclerViewAdapter(list,getContext());
adapter.setOnItemClickListener(new CategoryRecyclerViewAdapter.ClickListener() {
#Override
public void onItemClick(int position, View v) {
switch (position){
case 0:
getFragmentManager().beginTransaction().replace(R.id.frameLayout_inspiring,new Inspiring()).addToBackStack(null).commit();
}
}
});
recyclerView.setAdapter(adapter);
return view;
}
}
Inspiring :-
public class Inspiring extends Fragment {
public Inspiring() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_inspiring, container, false);
}
}
Pager Adapter :-
public class Pager extends FragmentStatePagerAdapter {
int tabCount=0;
public Pager(FragmentManager fm,int tabCount) {
super(fm);
this.tabCount=tabCount;
}
//this will return tab selected
#Override
public Fragment getItem(int i) {
switch(i) {
case 0:
return new Recents();
case 1:
return new Top();
case 2:
return new Categories();
default:
return null;
}
}
#Override
public int getCount() {
return tabCount;
}
}
You might find the AndroidViewModel of use in this case.
What you are doing is attempting to maintain state between different parts of your app.
If you have an AndroidViewModel attached to the Activity Lifecycle, you can observe that state in your Activity and make transactions to the FragmentManager to represent your choices.
An example
ViewModel
This ViewModel contains state data for which navigation item you are in (representing a Fragment with an integer in this case) and using an integer to represent an index for your inspiration row.
public class NavigationViewModel extends AndroidViewModel {
private MutableLiveData<Integer> navigationLiveData = new MutableLiveData<>();
private MutableLiveData<Integer> inspirationLiveData = new MutableLiveData<>();
public NavigationViewModel(#NonNull Application application) {
super(application);
}
public LiveData<Integer> getNavigation() {
return navigationLiveData;
}
public void setNavigation(Integer id) {
navigationLiveData.postValue(id);
}
public LiveData<Integer> getInspiration() {
return inspirationLiveData;
}
public void setInspiration(Integer id) {
inspirationLiveData.postValue(id);
}
}
Activity
The Activity will observe the navigation LiveData provided by our implementation of the AndroidViewModel. This will let it know immediately when a navigation change has been made.
public class NavigationActivity extends AppCompatActivity {
private NavigationViewModel navigationViewModel;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
navigationViewModel = ViewModelProviders.of(this).get(NavigationViewModel.class);
navigationViewModel.getNavigation().observe(this, id -> {
switch(id) {
case R.id.recents:
// TODO: Load recent fragment here with a transaction
break;
case R.id.top:
// TODO: Load top fragment here with a transaction
break;
case R.id.categories:
// TODO: Load categories fragment here with a transaction
break;
case R.id.inspiring:
// TODO: Load inspiring fragment here with a transaction
break;
}
});
}
}
Inspiration Fragment
This Fragment will observe the inspiration index provided by our implementation of AndroidViewModel. That lets it know what content needs to be displayed. This can be set from ANYWHERE.
public class InspiringFragment extends Fragment {
private NavigationViewModel navigationViewModel;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_inspiring, container, false);
navigationViewModel = ViewModelProviders.of(this).get(NavigationViewModel.class);
navigationViewModel.getInspiration().observe(getViewLifecycleOwner(), inspiration -> {
// TODO: Update the root view UI with data gleaned using the inspiration index given here
});
return root;
}
}
Setting it
Once you have that, all you need to do is call:
navigationViewModel.setInspiration(1);
navigationViewModel.setNavigation(R.id.inspiration);
This should give you a good base to start with.
I have one MainActivity and two fragments. In FragmentA I have a recycler view. If I click on "add" button there, the FragmentB is open. The thing I would like to is to write text into some EditTexts and send data back to FragmentA (and render that data in the recycler view). Could you suggest me something please? Thanks
FragmentB
public class NewContactFragment extends Fragment {
EditText name, number, email;
public String mName;
public String mNumber;
public String mEmail;
boolean isFavourite = false;
public NewContactFragment() {
// Required empty public constructor
}
public static NewContactFragment newInstance() {
NewContactFragment fragment = new NewContactFragment();
Bundle bundle = new Bundle();
fragment.setArguments(bundle);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
super.onCreate(savedInstanceState);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
//set title
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.new_contact);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_new_contact, container, false);
name = (EditText) view.findViewById(R.id.ed_name);
number = (EditText) view.findViewById(R.id.ed_number);
email = (EditText) view.findViewById(R.id.ed_email);
mName = name.getText().toString();
mNumber = number.getText().toString();
mEmail = email.getText().toString();
return view;
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.new_contact_menu, menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_done:
//TODO: save editTexts and return to ContactListFragment
break;
case R.id.action_favourite:
getActivity().invalidateOptionsMenu();
//Toast.makeText(getContext(), "isFavourite is: " + isFavourite, Toast.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
FragmentA
public class ContactListFragment extends Fragment implements View.OnClickListener {
private static final String TAG = "newcontact";
FloatingActionButton fabButton;
SearchView searchView;
RecyclerView recyclerView;
ContactsAdapter contactsAdapter;
List<Contact> mContact = new ArrayList<>();
public static ContactListFragment newInstance() {
Bundle args = new Bundle();
ContactListFragment fragment = new ContactListFragment();
fragment.setArguments(args);
return fragment;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_contact_list, container, false);
searchView = (SearchView) view.findViewById(R.id.search_view);
fabButton = (FloatingActionButton) view.findViewById(R.id.fab_button);
fabButton.setOnClickListener(this);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mContact = SugarRecord.listAll(Contact.class);
contactsAdapter = new ContactsAdapter(getActivity(), mContact);
recyclerView.setAdapter(contactsAdapter);
inputFilter();
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this, view);
//show actionBar
((MainActivity) getActivity()).getSupportActionBar().show();
//show title
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.app_name);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
public void inputFilter() {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
contactsAdapter.filterList(newText);
return true;
}
});
}
#Override
//Fab button listener
public void onClick(View v) {
((MainActivity) getActivity()).showFragment(new NewContactFragment(), TAG);
}
Fragments should generally only communicate with their direct parent activity. Fragments communicate through their parent activity allowing the activity to manage the inputs and outputs of data from that fragment coordinating with other fragments or activities. Think of the Activity as the controller managing all interaction with each of the fragments contained within.
A few exceptions to this are dialog fragments presented from within another fragment or nested child fragments. Both of these cases are situations where a fragment has nested child fragments and that are therefore allowed to communicate upward to their parent (which is a fragment).
The important thing to keep in mind is that fragments should not directly communicate with each other and should generally only communicate with their parent activity. Fragments should be modular, standalone and reusable components. The fragments allow their parent activity to respond to intents and callbacks in most cases.
There are three ways a fragment and an activity can communicate:
Bundle - Activity can construct a fragment and set arguments
Methods - Activity can call methods on a fragment instance
Listener - Fragment can fire listener events on an activity via an interface
In other words, communication should generally follow these principles:
Activities can initialize fragments with data during construction
Activities can pass data to fragments using methods on the fragment instance
Fragments can communicate up to their parent activity using an interface and listeners
Fragments should pass data to other fragments only routed through their parent activity
Fragments can pass data to and from dialog fragments
Fragments can contain nested child fragments
Read more about Fragment and its communication at Creating and Using Fragments
I have created two fragments in a ViewPager , when I click on first one , Second fragment is taking the click.
This issue puts me in another position, when I create two instance from same fragment but with different data.
{
#Override
public Fragment getItem(int index) {
switch (index) {
case 1:
return FragmentBrandList.getInstance(tabs.getBrandList2(), 19,
title);
case 0:
return FragmentBrandList.getInstance(tabs.getBrandList1(), 19,
title);
}
return null;
}
#Override
public int getCount() {
return 2;
}
}
After creating ViewPager , both the fragments get created correctly , but when I click on any thing in the first fragment , the click event gets fired in second fragment not in the first fragment.
EDIT
public class TabsPagerAdapter extends FragmentPagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int index) {
switch (index) {
case 1:
return FragmentBrandList.getInstance(tabs.getBrandList2(), 19,
title);
case 0:
return FragmentBrandList.getInstance(tabs.getBrandList1(), 19,
title);
}
return null;
}
#Override
public int getCount() {
return 2;
}
in FragmentBrandList
public class FragmentBrandList extends Fragment {
ArrayList<Brand> brandList = new ArrayList<Brand>();
int discoverID;
RecyclerView listView;
LinearLayoutManager mLayoutManager;
public static FragmentBrandList getInstance(ArrayList<Brand> brandList,
int discoverID, String title) {
FragmentBrandList frag = new FragmentBrandList();
Bundle b = new Bundle();
b.putSerializable("brandList", brandList);
b.putInt("discoverID", discoverID);
b.putString("title", title);
frag.setArguments(b);
return frag;
}
public FragmentBrandList() {
}
String title = "";
View v;
boolean isInflated = false;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (v == null) {
v = inflater.inflate(R.layout.fragment_list_view_brownbg,
container, false);
isInflated = true;
} else {
isInflated = false;
((ViewGroup) v.getParent()).removeView(v);
}
return v;
}
MainActivity activity;
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (isInflated) {
activity = (MainActivity) getActivity();
initView();
}
}
public void initView(){
title = getArguments().getString("title");
discoverID = getArguments().getInt("discoverID");
listView = (RecyclerView) v.findViewById(R.id.listView);
mLayoutManager = new LinearLayoutManager(getActivity());
listView.setItemAnimator(new DefaultItemAnimator());
listView.setHasFixedSize(true);
listView.setLayoutManager(mLayoutManager);
listView.setAdapter(new BrandListRecAdapter(getActivity(),
R.layout.single_item_listview, brandList));
}
#Override
public void onResume() {
// handle on click
((BrandListRecAdapter) listView.getAdapter())
.setOnItemClickListener(new ItemClickListener() {
#Override
public void onItemClickListener(final int pos, View v) {
activity.replaceCurrentFragment(
FragmentBrandDetails.getInstance(
brandList.get(pos), "bank"), true,
true);
}}
EDIT
i think problem cause
when create second fragment , listview.onclick is overwrite first one !!
how can solve this peb?
EDIT
thank you to every one try to help me
problem is already because i use same adapter and same fragment
when second fragment created it is overwrite on item click
so when click in item is called second one !!!
Just put this android:clickable="true" in every fragment layout, and this will not happen again.
This is just an educated guess, but because a ViewPager will always create at least one extra Fragment on either side of the currently visible fragment, you may be creating two virtually identical Fragments in parallel, assigning them both onItemClickListeners in onResume and as such they are both responding to item clicks when an item is pressed on either Fragment.
You could try moving the onItemClickListener to the ViewHolder in your Adapter, rather assigning it in onResume. In addition, I wonder what a Brand object looks like in your RecyclerView, and whether it wouldn't be simpler to pass the current ViewPager page as a parameter in getInstance, and use this to access an Array containing the information necessary to fill your RecyclerView rows.
Here is a very brief example of how your ViewHolder may look:
class MyRecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
public MyRecyclerViewHolder(View itemView) {
itemView.setOnClickListener(this);
//etc.
I'm trying to do something pretty basic but can't seem to get it to work.
I have a ViewPager and am using a FragmentPagerAdapter to populate it with fragments. I always have 3 fragments (call them A, B, C) and on fragment C I have a simple ListView. Whenever the user clicks an item on that ListView, I want to add a new fragment (Fragment D) to the ViewPager which will show details related to that list item.
If the user goes back to Fragment C, they can click on another list item and the contents of Fragment D should be updated with other details.
This is the code for the PageAdapter:
public class TopPagerAdapter extends FragmentPagerAdapter {
private final ArrayList<Fragment> fragments = new ArrayList<Fragment>();
public TopPagerAdapter(FragmentManager fm) {
super(fm);
fragments.add(0, new FragmentA());
fragments.add(1, new FragmentB());
fragments.add(2, new FragmentC());
}
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
#Override
public int getCount() {
return fragments.size();
}
#Override
public CharSequence getPageTitle(int position) {
return null;
}
public void addFragmentD(FragmentD frag) {
fragments.add(3, frag);
notifyDataSetChanged();
}
public void removeFragmentD() {
fragments.remove(3);
notifyDataSetChanged();
}
}
And this is how it is used (when the user clicks on a list item in Fragment C):
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
FragmentD frag = new FragmentD();
Bundle args = new Bundle();
args.putString("name", mName.getText().toString());
frag.setArguments(args);
adapter.addFragmentD(frag);
}
});
And this is the actual code of Fragment D (all it does is get the bundle that is passed to it and display it):
public class FragmentD extends Fragment {
private Context mContext;
private TextView mName;
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.mContext = activity;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_d, container, false);
mName= (TextView) view.findViewById(R.id.name);
String name = (String) getArguments().get("name");
mName.setText(name);
return view;
}
}
The end result is that FragmentD gets added correctly and it displays the correct info that gets passed to it via the Bundle, but it only works the first time. If I go back to FragmentC and click on another list item, that same FragmentD shows up and even though I am creating a new instance of FragmentD, its onCreateView method never get called. It's as if it stays in memory and never removed.
Any ideas how to make this work? Thanks.