without with viewpager tablayout tab showing practice pageradapter not fragments example best and android android-fragments xamarin.android fragmentpageradapter

with - viewpager tablayout android example



FragmentPagerAdapter solo existe en Android.Support.V4.App(y no en Android.App) (3)

Agregue esta dependencia a las dependencias de Gradle:

compile ''com.android.support:support-v13:+''

Y use android.support.v13.app.FragmentPagerAdapter esta manera (simplemente modifiqué el proyecto de demostración oficial en android studio: archivo → nuevo → nuevo proyecto → siguiente → siguiente → actividad con pestañas → siguiente → finalizar):

import android.app.Fragment; import android.app.FragmentManager; import android.support.v13.app.FragmentPagerAdapter; import com.google.android.gms.maps.MapFragment; /** A simple FragmentPagerAdapter that returns a MapFragment and a PreferenceFragment. */ public class MainActivityAdapter extends FragmentPagerAdapter { private MapFragment mapFragment; private PreferencesFragment preferencesFragment; public MainActivityAdapter(FragmentManager fm) { super(fm); mapFragment = MapFragment.newInstance(); preferencesFragment = new PreferencesFragment(); } @Override public int getCount() { return 2; } @Override public Fragment getItem(int position) { switch (position) { case 0: return mapFragment; case 1: return preferencesFragment; default: return null; } } }

No puedo encontrar FragmentPagerAdapter dentro de Android.App.

No quiero usar Fragment''s de Android.Support.V4.App, ya que mi API objetivo es 14 y superior (Android 4.0 y superior). Por lo tanto, solo quiero usar plain de Android.App.Fragments y las clases asociadas.

Solo lo encontré en Android.Support.V4.App, pero esto no es suficiente para mí, porque estoy intentando usar Android.App.Fragment''s (no Android.Support.V4.App.Fragment''s) y allí clases relacionadas dentro de Android.App (no Android.Support.V4.App), y mi código no se compilará si obtengo mi paginador de FragmentPagerAdapter si es de la biblioteca de soporte, debido a la falta de coincidencia de tipos entre Android.App y Android.Support .V4.App.

Al igual que con el caso aquí No se puede convertir a android.app.Fragment , ¿hay una clase de buscapersonas "normal" (PagerAdapter) que debería usar en lugar de FragmentPagerAdapter o algo así (al igual que se deriva de la actividad normal, y no de FragmentActivity, cuando se dirige a API 11 o superior).

Aquí está el código de muestra con el que estoy trabajando (es el archivo FragmentPagerSupport.cs dentro de la solución Support4.sln de los ejemplos de MonoDroid que se encuentran en https://github.com/xamarin/monodroid-samples/tree/master/Support4 ).

He comentado las líneas que hacen referencia a Android.Support.V4.App y las reemplacé con código que hace referencia a Android.App. No hay FramePagerAdapter fuera de Android.Support.V4.App que pude encontrar, y realmente lo necesito).

Gracias.

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; //using Android.Support.V4.App; //using Android.Support.V4.View; namespace Support4 { [Activity (Label = "@string/fragment_pager_support")] [IntentFilter (new[]{Intent.ActionMain}, Categories = new[]{ "mono.support4demo.sample" })] //public class FragmentPagerSupport : FragmentActivity public class FragmentPagerSupport : Activity { const int NUM_ITEMS = 10; MyAdapter adapter; ViewPager pager; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView(Resource.Layout.fragment_pager); //adapter = new MyAdapter(SupportFragmentManager); adapter = new MyAdapter(FragmentManager); pager = FindViewById<ViewPager>(Resource.Id.pager); pager.Adapter = adapter; var button = FindViewById<Button>(Resource.Id.goto_first); button.Click += (sender, e) => { pager.CurrentItem = 0; }; button = FindViewById<Button>(Resource.Id.goto_last); button.Click += (sender, e) => { pager.CurrentItem = NUM_ITEMS - 1; }; } // ????????????????????????????????????????????????? // - where is FragmentPagerAdapter // ????????????????????????????????????????????????? protected class MyAdapter : FragmentPagerAdapter { public MyAdapter(FragmentManager fm) : base(fm) { } public override int Count { get { return NUM_ITEMS; } } public override Fragment GetItem (int position) { return new ArrayListFragment(position); } } protected class ArrayListFragment : ListFragment { int num; public ArrayListFragment() { } public ArrayListFragment(int num) { var args = new Bundle(); args.PutInt("num", num); Arguments = args; } public override void OnCreate (Bundle p0) { base.OnCreate (p0); num = Arguments != null ? Arguments.GetInt("num") : 1; } public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var v = inflater.Inflate(Resource.Layout.fragment_pager_list, container, false); var tv = v.FindViewById<TextView>(Resource.Id.text); tv.Text = "Fragment #" + num; return v; } public override void OnActivityCreated (Bundle p0) { base.OnActivityCreated (p0); ListAdapter = new ArrayAdapter<string>(Activity, Android.Resource.Layout.SimpleListItem1, Cheeses.cheeseStrings); } public override void OnListItemClick(ListView l, View v, int position, long id) { Console.WriteLine ( "Item clicked: " + id); } } } }


Hay uno que está en android.support.v13.app.FragmentPagerAdapter , que debe hacer lo que usted quiere que haga. Es un FragmentPagerAdapter para fragmentos que no son de soporte.

Instalación de Android Studio

Por favor, agrega las siguientes dependencias de Gradle

dependencies { compile ''com.android.support:support-v13:+'' }


Uf, solo necesitas usar el FragmentPagerAdapter de la biblioteca de soporte V13

Android.Support.V13.App.FragmentPagerAdapter

Luego, todas las demás clases relacionadas con Fragment se pueden usar desde las bibliotecas / espacios de nombres "normales", con la excepción de ViewPager, pero eso no es gran cosa.

Aquí hay una muestra para completar (ejemplo de "Support4" modificado de https://github.com/xamarin/monodroid-samples/ ):

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Util; using Android.Views; using Android.Widget; using Java.Lang; using Android.Support.V4.View; using Fragment = Android.App.Fragment; namespace Support4 { [Activity (Label = "@string/fragment_pager_support")] [IntentFilter (new[]{Intent.ActionMain}, Categories = new[]{ "mono.support4demo.sample" })] public class FragmentPagerSupport : Activity //public class FragmentPagerSupport : FragmentActivity { const int NUM_ITEMS = 4; protected MyAdapter _pagerAdapter; protected ViewPager _viewPager; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView(Resource.Layout.fragment_pager); List<Fragment> fragments = new List<Fragment>(); // *** MonoDroid 4.2.7 letter case bug *** make''s first letter lower. //string typeName = typeof(Fragment1).FullName; string typeName = "support4." + typeof(Fragment1).Name; fragments.Add(Fragment.Instantiate(this, typeName)); fragments.Add(Fragment.Instantiate(this, typeName)); fragments.Add(Fragment.Instantiate(this, typeName)); fragments.Add(Fragment.Instantiate(this, typeName)); //adapter = new MyAdapter(SupportFragmentManager); _pagerAdapter = new MyAdapter(FragmentManager, fragments); _viewPager = FindViewById<ViewPager>(Resource.Id.view_pager); _viewPager.Adapter = _pagerAdapter; } public override bool OnTouchEvent(MotionEvent e) { return base.OnTouchEvent(e); } protected class MyAdapter : Android.Support.V13.App.FragmentPagerAdapter { private List<Fragment> _fragments; public override Java.Lang.Object InstantiateItem(View p0, int p1) { return base.InstantiateItem(p0, p1); } public MyAdapter(Android.App.FragmentManager fm) : base(fm) { } //public MyAdapter(Android.Support.V4.App.FragmentManager fm, List<Android.Support.V4.App.Fragment> fragments) // : base(fm) public MyAdapter(FragmentManager fm, List<Fragment> fragments) : base(fm) { _fragments = fragments; } public override int Count { get { return NUM_ITEMS; } } //public override Android.Support.V4.App.Fragment GetItem(int p0) public override Fragment GetItem(int p0) { return _fragments[p0]; } public override float GetPageWidth(int p0) { //return base.GetPageWidth(p0); //base.GetPageWidth(p0); return (float)(0.5f); } } } //public class Fragment1 : Android.Support.V4.App.Fragment public class Fragment1 : Fragment { int num; private static int _colorIndex = 0; private static Android.Graphics.Color[] _colors = new[] { Android.Graphics.Color.Aqua, Android.Graphics.Color.DarkViolet, Android.Graphics.Color.Coral, Android.Graphics.Color.Bisque}; public Fragment1() { } public Fragment1(int num) { var args = new Bundle(); args.PutInt("num", num); Arguments = args; } public override void OnCreate(Bundle p0) { base.OnCreate(p0); num = Arguments != null ? Arguments.GetInt("num") : 1; } public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.Inflate(Resource.Layout.aaaaa, container, false); TextView tv = v.FindViewById<TextView>(Resource.Id.text); tv.Text = "# " + _colorIndex; tv.SetBackgroundColor(_colors[_colorIndex++]); return v; } public override void OnActivityCreated(Bundle p0) { base.OnActivityCreated(p0); } } }

<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2010 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Top-level content view for the simple fragment sample. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:padding="4dip" android:layout_width="match_parent" android:layout_height="match_parent"> <!--android:gravity="center_horizontal"--> <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="700dip" android:layout_height="match_parent" android:layout_weight="1" android:background="#FFCCFFFF"> <!--android:layout_width="match_parent"--> </android.support.v4.view.ViewPager> </LinearLayout>

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen_container" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/hello_world" android:background="#FF335555"/> </LinearLayout>