-1

im new to programming.. i'm building an app with a about 18 buttons.. after clicking the button it takes me to a new activity..

the new activity layout is the same for all the buttons but i want to change the text (title and text).

e.g. activity1 is a list of buttons of football clubs (Barcelona, Madrid,...etc). once clicked it will take you to activity 2 which displays the information about the club (text).

Must i create an activity for each of all 18 buttons? (imagine if each button has a few more buttons and that will multiply to over 50 activities and all the classes asociated with them)

Is there a way i can code my target page to use the same layout but just pull different stings of text which corresponds to the button?

Appreciate all the help.. thanks allot!

Zeuss
  • 5
  • 2
  • 1
    Welcome to Stackoverflow. please visit http://stackoverflow.com/help/how-to-ask – Krupesh Kotecha Dec 04 '15 at 10:15
  • Thanks allot guys... ended up using SharedPrefrences... worked like a charm! – Zeuss Dec 05 '15 at 09:08
  • another related Question: i have managed to use SharedPreferences to display text in next activity... now.. within the next activity there's a button which when click will open a webview with the club's website... how do i link it using sharedPreference? – Zeuss Dec 05 '15 at 14:08

3 Answers3

0

Just start the same Activity again and keep some kind of index either in the Application class, a Database or SharedPreference use this index to keep track of what you should be displaying in each instance of the same Activity.

You can start the same Activity as many times as you want and it will still be treated as a separate one and the back stack will still function the same.

vguzzi
  • 2,420
  • 2
  • 15
  • 19
0

Use same Activity and same layout and pass some indicator to activity or pass title and text from current activity to next activity and display title and text accordingly

Hunain
  • 385
  • 5
  • 15
0

It sounds like you want to change only text.so you can keep track of which button is clicked in your previous activity. You can store that value you are using to keep track which button clicked into 1)SharedPreference and retrive into another activity link for how to use it. 2)Intents -Store value into intent and pass to another activity and retrive it.(You can use bundle too here) link for how to use it After retriving value you can use setText("") function hope it will help you

Community
  • 1
  • 1
Dhiraj
  • 870
  • 2
  • 12
  • 25
  • thank you Dhiraj for your answer... it was helpful with the links.. do you know of any youtube video which can help me achieve this? as i said... i'm very new to this.. – Zeuss Dec 04 '15 at 15:52
  • @Zeuss This is link of youtube video for SharedPreference https://www.youtube.com/watch?v=E1tQ6dPaqLs – Dhiraj Dec 04 '15 at 16:10
  • @Zeuss This is link of youtube video for passing value through intents https://www.youtube.com/watch?v=0ism1OM0an0 – Dhiraj Dec 04 '15 at 16:12
  • setContentView(webview); SharedPreferences settings = getSharedPreferences(contentPreferencess, 0); String myPdfUrl = (settings.getString ("fileURL",null)); String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl; webview.loadUrl(url); how do i get the webview to pull the string from my sharedpreferences for the url?? – Zeuss Dec 05 '15 at 16:07
  • @Zeuss if it is another question then please post with details – Dhiraj Dec 07 '15 at 04:44