Dynamic use of viewswitcher / viewflipper
-
12-12-2019 - |
Question
I have a file toto.xml with a layout that contains a TextView and a ImageView. and I have another file main.xml that contains a ViewSwitcher.
the question: How to integrate toto.xml in ViewSwitcher dynamically with different content and editable in the Main.java
thank you
PS: Sorry if my English is poor but this text is translated by Google Translator
Solution
After more than a week of research :
when the firstly ViewSwitcher can only have two views on this we must use the ViewFlipper secondly: to fill a ViewSwitcher by more views that can scroll it is very simple:
flipper.addView (View v);
knowing that the View can be a TextView or even a LinearLayout which contains one or more textview, so we can use a loop that will fill the view from the database and then call switcher.addView ();
Example:
ViewFlipper flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
flipper.addView (addText("Stackoverflow Forever"));
public View addText(String text) {
TextView tv = new TextView(this);
tv.setText(text);
return v;
}
Thank you anyway;)