Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialElsa Marie W.
337 Pointspages loading new button destination
Hello!
Hopefully I will find a solution for my problem here. So I worked with the "Creating an Interactive Story" Course from Ben Jakuben lately and followed his steps through creating an app.
But now I have a problem: I want to create two seperated activities - one for displaying the text (textMain) and one for picking an answer (choiceMain). On the textMain Activity is a button displayed, that is loading new content, if the next page is text only, or it is leading to the choiceMain activity for picking an answer.
For this I created 2 Buttons on textMain. Button1 loads new content, Button2 moves you to the choiceMain activity. As said in the video, I created 4 java classes:
[choice] including: private int bTextId; (button text) private int nextPage; (destination)
[pageChoice] including: private choice choiceA; private choice choiceB; private choice choiceC; private choice choiceD; private choice choiceE;
[pageText] including: private int imageId; (for Image) private int textId1; (for TextView1) private int textId2; (for TextView2 - should be invisible if not used) private int bNextId; (Button1) private int bChoiceId; (Button2)
[story] including: private pageText[] textpage; ...
Pretty far until down here, thanks for still bothering :) So now I want to tell Button1 that on page1 it's visibility should be "visible" and it should load the content for page 2. But on page 2 it's visibility should change to "gone" and instead Button2 (which was "gone" before) should change to "visible" and lead to choiceMain. (that was my solution, I'm open for new suggestions) ALSO choiceMain should display the choices fitting to page2 and if I pick a choice, it should lead back to textMain and display the next page fitting to the made choice.
so how do i tell the buttons (and textViews) to change their visibility depending on the shown page and how do i tell them to change their destination depending on a choice made in another activity? any suggestion, or even links to refering toutorials would be helpful! if needed, i can copy my java/xml code ofc.
thanks for attention!
1 Answer
Elsa Marie W.
337 PointsWhich part of code exactly? Well I just build a sample, so here's my main activity xml file: (pretty standard)
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/button3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@string/Lorem"
tools:textColor="#e3e4ea" />
<Button1
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/button4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button2
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/button6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button3
android:id="@+id/button6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
So everything I want to achieve first, is that the TextView changes it's content depending on which button I choose. So Button 1 leads to text1 and so on. Quiet simple, BUT I also want that the Buttons change too. So after Button1 lead to let's call it page 2, the buttons have to change and lead to page 3,4,5. Another problem is that not every page has buttons, so I have to hide them on text-only pages. I know how to achieve the single targets, but I don't know how I can make them rliable to the users choices. Well the goal is to create an interactive story app with much more choices - maybe that helps understanding.
thanks for help, I hope you understand. Ask for more if you need information. greets.
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherHi Elsa! Could you post your code? I think I've got a good idea of what's going on, but I want to be sure :)