Thank you in advance for any help.
I would like to inject different strings in a Fragment but I’m not sure how.
The code that I borrowed to clunk things together at this point is:
public class MyFragment extends Fragment{
int mCurrentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Getting the arguments to the Bundle object */
Bundle data = getArguments();
/** Getting integer data of the key current_page from the bundle */
mCurrentPage = data.getInt("current_page", 0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfragment_layout, container,false);
TextView tv = (TextView ) v.findViewById(R.id.tv);
tv.setMovementMethod(new ScrollingMovementMethod());
tv.setText("You are viewing the page #" + mCurrentPage + "\n\n" +"\n\n" + "Swipe Horizontally left / right");
return tv;
}
This does what I want it to do, only I want to display different strings of text depending on which page it is on. I see in this example code that it is possible to update the page number (mCurrentPage), but I want to correlate that with different text strings.
Thank you!
Simply put the setText() into a switch case e.g: