How do I start a new Activity using Intent from PagerAdapter class? This is how my ViewPagerAdapter class looks like.
public class ViewPagerAdapter extends PagerAdapter
This is how I am trying to start new activity in the OnClickListner method of the ViewPagerAdapter
@Override
public void onClick(View v) {
// Page is clicked
NewsItem item = ViewPagerAdapter.this.newsItems.get(position);
Log.w("TAP ON NEWS ITEM ", item.getTitle());
// start ImageViewer Activity
Intent readMore = new Intent(getActivity(), ReadMoreActivity.class);
startActivity(readMore);
}
});
getActivity()
and startActivity
method's not available in PagerAdapter
. so use v.getContext()
for preparing Intent and calling startActivity
method :
Intent readMore = new Intent(v.getContext(), ReadMoreActivity.class);
v.getContext().startActivity(readMore);