-1

I am a beginner and this is my first app. I am making an app that will show the user Text View in the mainActivity.xml, ex.Music, then the user can click on the 'music' text View(via intent) , and it goes to another activity where are displayed several other text views. ex. Rap, Pop, Rock, Punk ... each of these views can be clicked (with intent), and again it leads to another activity, where are displayed various sub-genres of let's say Rock, and the user can click on one of them and then it shows some text views with name of the songs of that genre and if clicked the final intent leads the user to the Youtube app. The 'problem' is that I have to create new class and new activity for every genre, create text view with id in xml layout , define intent in the class with setOnClickListener and goes to another activity. If i do this for every genre, I may need more than 200+ classes and layouts for the whole app. Is there some way to make a one root layout xml, and just in every class use that layout but with different text in text views. Also can i somehow reduce the number of classes needed for this ?

I tried with ArrayList<> to add the text in text views but i can't find the id so that i can call the intent.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • You create a single Activity and layout, pass in a parameter via the Intent that starts it to decide what to show, and change the text of the views at runtime in the Activity. This is kind of basic programming, if you need help on this level I'd advise you to seek a mentor (which is beyond the scope of this site). – Gabe Sechan Mar 25 '19 at 14:58

1 Answers1

0

You can send data trough the intent and then set this data to the textfield

In your sender Activity

Intent myIntent = new Intent(this, GenreClass.class);
myIntent.putExtra("genre","rock");
startActivity(myIntent);

In the receiver Activity

 Intent myIntent = getIntent(); 
 String genre = myIntent.getStringExtra("genre");
 myTextView.setText(genre)
John Joe
  • 12,412
  • 16
  • 70
  • 135
Pablo R.
  • 711
  • 2
  • 10
  • 31