如何使我的应用程序从一开始加载文章?

时间:2016-02-17 08:21:04

标签: java android

我有一个简单的应用程序有50篇文章,我的上一个和下一个按钮在所有选择中都很好但是当用户走到最后(第50篇文章)时,应用程序无法从第一篇文章的开头再次加载。 感谢您的帮助,这是我的代码: 我不知道是否需要更多明白,因为我是新手。

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);
            }
        });
    }}
}

0 个答案:

没有答案