Reputation: 1875
I have a fragment, where you actually have 3 pages, you can swipe with. On each page you have a default String like this "Hello World from section: %1$d" which is saved in strings. xml "
And the fragment java class method looks like this:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_generaldiscription, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
textView.setText("test"); // testing purposes
return rootView;
}
}
My question is: I don't want every page to have the same Text. Section 1 has "Hello world from section: 1" , section 2 has "Hello world from section: 2"
I want that section 1 has a different string like "hello, this is section 1 of your fragment." How can I adress the different sections in my fragment in order to show different strings?
Thank you.
Upvotes: 0
Views: 378
Reputation: 73
It seems that you need a variable to show diffenent strings.That's why the strings.xml doesn't work.
Here is my solution
Step1:
custom a constructor which contains a String object to descripbe the textview
Step2:
Init three fragments objects with different strings in your FragmentAdapter class
Step3: Test it whther it can work
Well.The code is a little tedious,It's not convinent for me to write here.Just try, you can get it :)
Upvotes: 1
Reputation: 70
I think on every page u got "Hello world from section: 1" and if u add another text on section 2 page it overlaps the both the text into one another. I got that problem, then i use android:background="#ffffff" in layout so section 1 text becomes white due to background colour, if u want another colour or image set in background. and then section 2 will show only "Hello world from section: 2" set it through xml. This is not perfect solution but it works for me.
Upvotes: 1
Reputation:
It looks like a pain in the ass to deal with.
I like to use Cheesesquare instead. To add a page you just need:adapter.addFragment(new CheeseListFragment(), "Category 1");
, and customisations are done within fragment class
Upvotes: 2