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 trialEleni Minadaki
3,687 PointsHow can reload the 0 page ?
Hi treehousers! I have stuck! I need to reload the 0 page when articles of the app has been to the end and to hide the previous Button only when the app shows my first article ( 0 page). Because there is no need the user see the previous button when he can't choose it. Thanks for any help.
public class StoryActivity extends AppCompatActivity {
public static final String TAG = StoryActivity.class.getSimpleName();
private Story mStory = new Story();
private ImageView mImageView;
private TextView mTextView;
private Page mCurrentPage;
private String mName;
private Button mPreviousButton;
private Button mNextButton;
private ScrollView mScrollView;
private Button mStartButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story2);
//Intent intent = getIntent();
//mName = intent.getStringExtra(getString(R.string.key_name));
if(mName == null){
mName = "";
}
Log.d(TAG, mName);
mImageView = (ImageView)findViewById(R.id.storyImageView);
mTextView = (TextView)findViewById(R.id.storyTextView);
mPreviousButton = (Button)findViewById(R.id.previousButton);
mNextButton = (Button)findViewById(R.id.nextButton);
mTextView.setMovementMethod(new ScrollingMovementMethod());
loadPage(0);
}
private void loadPage(int choice){
mCurrentPage = mStory.getPage(choice);
Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());
mImageView.setImageDrawable(drawable);
String pageText = mCurrentPage.getText();
//add the name if placeholder included.
//pageText = String.format(pageText,mName);
mTextView.setText(pageText);
if(mCurrentPage.isSingle()){
mPreviousButton.setVisibility(View.VISIBLE);
mNextButton.setText("");
mNextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
loadPage(0);
}
});
}else{
mPreviousButton.setText(mCurrentPage.getChoices().getText1());
mNextButton.setText(mCurrentPage.getChoices().getText2());
mPreviousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int previousPage = mCurrentPage.getChoices().getPreviousPage();
loadPage(previousPage);
}
});
mNextButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
int nextPage = mCurrentPage.getChoices().getNextPage();
loadPage(nextPage);
}
});
}}
}
package com.example.eleni.interactivestory.model;
import android.text.method.ScrollingMovementMethod;
/**
-
Created by Eleni on 16/12/2015. */ public class Page {
private int mPageId; private int mImageId; private String mText; private Choices mChoices; private boolean mIsSingle = false;
public Page(int pageId, int imageId, String text, Choices choices) {
mPageId = pageId; mImageId = imageId; mText = text; mChoices = choices;
}
public Page(int pageId, int imageId, String text) {
mPageId = pageId; mImageId = imageId; mText = text; mChoices = null; mIsSingle = true;
} public int getPageId(){ return mPageId; }
public void setPageId(int pageId){ mPageId = pageId; }
public int getImageId() { return mImageId; }
public void setImageId(int imageId) { mImageId = imageId; }
public String getText() { return mText; }
public void setText(String text){ mText = text; }
public Choices getChoices(){ return mChoices; }
public void setChoices(Choices choices){ mChoices = choices; }
public boolean isSingle() { return mIsSingle; } public void setSingle(boolean isFinal) { mIsSingle = isFinal; }
}
public class Choices { private String mText1; private String mText2;
private int mPreviousPage;
private int mNextPage;
public Choices(int currentPage, String text1, String text2) {
mPreviousPage = currentPage - 1;
mText1 = text1;
mNextPage = currentPage + 1;
mText2 = text2;
}
public String getText1() {
return mText1;
}
public void setText1(String text1) {
mText1 = text1;
}
public String getText2(){
return mText2;
}
public void setText2(String text2){
mText2 = text2;
}
public int getPreviousPage() {
return mPreviousPage;
}
public void setPreviousPage(int previousPage){
mPreviousPage = previousPage;
}
public int getNextPage() {
return mNextPage;
}
public void setNextPage(int nextPage) {
mNextPage = nextPage;
}
}