I have a Fragment(A) with a TextView with value “XXXX” set using setText() method. I replace Fragment(A) by Fragment(B) and then I replace B by A again.
When I do this, the value XXXX is gone in the Fragment(A) TextView. I tried calling the TextView.setText method in the onStart as well as the onResume methods – same result. When I debug the code, I can literally see that the setText method being used and the value XXXX is there. I printed it out on LogCat and it is there too, but I don’t see any values on the screen.
I tried googling and I couldn’t get an answer. I would appreciate any pointers.
Code
public void onResume() {
super.onResume();
String dData = readFileFromSDCard();
String dArray[] = dData.split(";");
txtName = (TextView) getActivity().findViewById(R.id.txtName);
txtName.setText("first name")
}
With fragments you can’t get the layout using
getActivity().findViewById(R.id.txtName);you should do it like this. This is called when also when you replace fragment B back to A.This code needs to stand in you Fragment class of course.