public boolean nextNews() { if (++newsID < currentCategory.getNews().size()) { FragmentTransaction ft = getFragmentManager().beginTransaction(); currentNews = currentCategory.getNews(newsID); NewsFragment fragment = NewsFragment.newInstance(currentNews); ft.replace(R.id.frNews, fragment); ft.commit(); return true; } return false; }
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "ArticleActivity OnCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_article); if (getSupportActionBar() != null) getSupportActionBar().hide(); currentCategory = getIntent().getParcelableExtra("current_category"); newsID = getIntent().getIntExtra("current_news", newsID); currentNews = currentCategory.getNews(newsID); FragmentTransaction ft = getFragmentManager().beginTransaction(); fragment = NewsFragment.newInstance(currentNews); ft.add(R.id.frNews, fragment); ft.commit(); btnPrevNews = (Button) findViewById(R.id.btnPrevNews); btnPrevNews.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (!prevNews()) finish(); } }); btnNextNews = (Button) findViewById(R.id.btnNextNews); btnNextNews.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { if (!nextNews()) finish(); } }); svMain = (ScrollView) findViewById(R.id.svMain); svMain.setOnTouchListener( new OnSwipeTouchListener(ArticleActivity.this) { public void onSwipeRight() { if (!prevNews()) finish(); } public void onSwipeLeft() { if (!nextNews()) finish(); } }); }