Best way to switch to another activity or text view

  • Replies:3
  • OpenNot stickiedUnanswered
  • Forum posts: 3

Sep 20, 2017 7:59:39 PM via Website

This question may be very basic and easy but very important for me. I tried to search online but no luck!

I am beginner to coding, java and Android studio. I am learning to develop Android app by online tutorials. I am trying to develop an app for thoughts and quotes. I have thousands of thoughts to add in the app. Below mentioned steps I am following now:
1. I create a new activity
2. I add a thought in it.
3. I add two buttons for next and previous thought/activity
4. I link next thought/activity to next button and previous thought/activity to previous button in java file.

I have to repeat these steps thousands time.

Is there any better and time saving way to do the same thing? For example, I create only one activity and write down all the thoughts in different paragraphs/text views. Next button display next paragraph/text view/thought & previous button display previous paragraph/text view/thought. Or any other better way?

  • Forum posts: 2

Sep 22, 2017 1:33:30 AM via Website

Hello,
I think it would be pretty straightforward to use only one activity.
Store all thoughts in an ArrayList. You can fill the list with data from database or just add items to it from your code.
Have a variable to keep track of which thought index to show, starting from 0.
Next and Previous buttons will update your textview content with the item from the arraylist and increment/decrement that index.

  • Forum posts: 3

Sep 23, 2017 6:52:18 AM via Website

Thank you Mehdi Aryan for your reply ☺

Because I am beginner, It would be great if you can provide the answer with more details. If you can provide sample code for Array list and step by step guidance it will be really great help for me or you can provide any link for the same.

Thanks again.

  • Forum posts: 3

Sep 23, 2017 7:49:49 AM via Website

Just make an arraylist and write down all your activities name in that list. Now where you want to go in next activity just start from 0 index and after each click of the button the index should also be sent to next activity from there you can ++ index or -- index for backward movement, This would be pretty easy but logic is little bit difficult You can try on your own just try to call 2 activites first by this method.