0

My spinner has 3 strings. Those are {India, china, usa}

If user select India then India.xml should be included in activity_main.xml

If user select china then china.xml should be included in activity_main.xml

If user select usa then usa.xml should be included in activity_main.xml

Is it possible? If yes, how to do it? If not, how can I acheive my requirement?

Any Help would be appreciated.

Levon Petrosyan
  • 8,815
  • 8
  • 54
  • 65

1 Answers1

0

Follow this guide buddy https://examples.javacodegeeks.com/android/core/app/fragment/android-fragments-example/

By following this guide you will be able to do your job just use spinner instead of buttons in this example then you are good to go

Muhammad Saad Rafique
  • 3,158
  • 1
  • 13
  • 21
  • Sir I am implementing this Fragment, in this case, will your guide helpful to me? –  Oct 26 '17 at 12:41
  • Best of luck do accept the answer if it helps and upvote .. only if it helps otherwise ignore it because your answer and upvote helps others too to achieve this . Happy coding bro :) – Muhammad Saad Rafique Oct 26 '17 at 12:41
  • I was implementing my code by taking that as a reference. Here I am facing problem. In fragment_one.xml I was implemented 4 cardviews and in fragment_two.xml i was implemented 1 cardview. When I am selecting 1st item in spinner, I need to display fragment_one.xml and When I am selecting 2nd Item in spinner I need to display fragment_two.xml. Now, here what happened is when I was selected 1st item It displays 4 cardviews in fragment_one.xml but when selected 2nd item It replaced the 1st card in fragment_one.xml and displayed remaining 3rd cards in fragment_one.xml. Why?help me. @M.Saad Lakhan –  Oct 26 '17 at 15:03
  • Please anyone can help me. I am almost done but at last I am facing this issue. –  Oct 26 '17 at 15:24
  • there should be an error bro ... Normally when new fragment loads it replaces the old one ... can you please share your code so I may look it? – Muhammad Saad Rafique Oct 27 '17 at 05:25