I have the following class:
the public class spread myFragment fragment {int mCurrentPage; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); / ** Get arguments for bundle objects / bundle data = getArguments (); Getting integer data of key current_page from / ** bundle * / mCurrentPage = data.getInt ("current_page", 0); } @Override Public View onCreateView (LayoutInflater inflater, ViewGroup container, bundled savedInstanceState) {v see = inflater.inflate (R.layout.myfragment_layout, container, false); TextView TV = (TextView) v.findViewById (R.id.tv); Tv.setText ("Você está no item" + mCurrentPage + "by menu" + "\ n \ n" + "deslize paras os lados para LED escolher an opcao"); return v;
< P> Where the oncreateview method is called only one layout, how do I call it a layout (slice) in each cache or swipe the View tab, mainly acts as a menu The following Class paraâmentro pear as Bandle method:
Public class MyFragmentPagerAdapter extends FragmentPagerAdapter {final integer PAGE_COUNT = 5; / ** class constructor * / public MyFragmentPagerAdapter (Fragment Manager FM) {super (FM);} / ** This method * to create a page / @Override public piece GetItem (int arg0) {MyFragment myFragment = new MyFragment () when will be active is requested; bundled data = new Bundle (); Data.putInt ( "current_page", arg0 + 1); myFragment.setArguments (data); return IFragment;} / ** number of pages / / Override public int getCount () {Return PAGE_COUNT; } @ Override Public Charsequence getPageTitle (return status) {Return "Pug" + (Status + 1); }
And this is the main looks:
public class MainActivity FragmentActivity extends {@Override public void OnCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState ); SetContentView (R.layout.activity_main); / ** View Layout ViewPager / Layout Detection / ViewPager Pager = (ViewPager) findViewById (R.id.pager); / ** Objects Jerena Framanto * / FragmentManer FM = MatchExportFragmentManager (); / ** Instanting FragmentPager Adapter * / MufragmentPager Adapter Pager Adapter = New MyFragmentPagerAdapter (FM); / ** Fixed Pager Adapter to Ozzy Pager * / Pageret Adapter (Pager Adapter); } @ Override Public Boolean On Crate Option Menu (menu menu) {getMenuInflater (). Flood (R. menu activation_men, menu); Back true; }}
and or XML main_activity:
& Lt; /android.support.v4.view.ViewPager> & Lt; Android: layout_height = "wrap_content" android: layout_alignParentTop = "true" Android: layout_centerHorizontal = "true" Android: layout_marginTop = "46dp" Android: Text: TextView Android: id = "@ + id / textView1" Android: layout_width = "wrap_content" = "Menu Head" Android: textcolor = "# 1E90FF" Android: Text-style = "bold" Android: typeface = "without" Android: textSize = "25sp" /> & Lt; / RelativeLayout & gt;
and myfragment.xml:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; TextView xmlns: android = "http://schemas.android.com/apk/res/android" android: id = "@ + id / TV" Android: layout_width = "match_parent" Android: layout_height = "match_parent" android: gravity = "Center" & gt; & Lt; / TextView & gt;
Send me code that may be ready to attract many goals to my goal, please!
Comments
Post a Comment