import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewPager pager = new ViewPager(this);
pager.setId(View.generateViewId());
pager.setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) {
@Override
public Fragment getItem(int position) {
return new MainFragment();
}
@Override
public int getCount() {
return 5;
}
});
setContentView(pager);
}
public static class MainFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView view = new TextView(getActivity());
view.setText("Fragment Text");
return view;
}
}
}