-1

I added a fragment into a container, and it's been added successfully:

DeviceItemFragment diFrag = new DeviceItemFragment();

FragmentManager fragManager = getFragmentManager();
FragmentTransaction fragTrans = fragManager.beginTransaction();

fragTrans.add(R.id.device_items, diFrag);
fragTrans.commit();

I want to set the text of a TextView in the fragment right after it's added, I tried getView().findViewById(xxx), but it got error because I can't get the view at the moment. So now I want to find a way to set the text after it's been 'rendered', is there any way to do this?

Tonitang
  • 41
  • 7

2 Answers2

1

Why dont you pass string for textview as a parameter in your fragment? Take a look here

How to use setArguments() and getArguments() methods in Fragments?

Maksym V.
  • 2,877
  • 17
  • 27
0

Yes, you can.

Override the onViewCreated in the DeviceItemFragment.java class.

This lifecycle method is called when the view has been created, hence you can find the view by id and update its content here.

Anmol
  • 448
  • 2
  • 6