Back to project page ResideLayout.
The source code is released under:
Apache License
If you think the Android project ResideLayout listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.yugy.github.residelayout; /*w w w .jav a2s . co m*/ import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.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 FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new SimplePagerAdapter(getSupportFragmentManager())); } private class SimplePagerAdapter extends FragmentPagerAdapter{ public SimplePagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { return SimpleFragment.newInstance(i); } @Override public int getCount() { return 5; } } public static class SimpleFragment extends Fragment{ private int mIndex; private TextView mView; public static SimpleFragment newInstance(int index){ SimpleFragment fragment = new SimpleFragment(); Bundle args = new Bundle(); args.putInt("index", index); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mIndex = getArguments().getInt("index"); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) { mView = new TextView(container.getContext()); mView.setBackgroundColor(Color.WHITE); return mView; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mView.setText("Fragment: " + mIndex); } } }