Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MAin Activity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V4.App;
using Android.Support.V4.View;
namespace ViewPagerDemo
{
[Activity (Label = "ViewPagerDemo", MainLauncher = true)]
public class MainActivity : FragmentActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
ViewPager pager = (ViewPager) FindViewById(Resource.Id.viewPager);
pager.Adapter = new MyPagerAdapter(this, SupportFragmentManager);
}


private class MyPagerAdapter : FragmentPagerAdapter
{
private readonly MainActivity outerInstance;
public MyPagerAdapter(MainActivity outerInstance, Android.App.FragmentManager fm) : base(fm)
{
this.outerInstance = outerInstance;

}

public override Android.App.Fragment GetItem(int pos)
{
switch (pos)
{

case 0:
return FirstFragment.newInstance("FirstFragment, Instance 1");
case 1:
return SecondFragment.newInstance("SecondFragment, Instance 1");
case 2:
return ThirdFragment.newInstance("ThirdFragment, Instance 1");
case 3:
return ThirdFragment.newInstance("ThirdFragment, Instance 2");
case 4:
return ThirdFragment.newInstance("ThirdFragment, Instance 3");
default:
return ThirdFragment.newInstance("ThirdFragment, Default");
}
}
}
public int Count
{
get
{
return 5;
}
}
}

}

Main.Xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"> android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.viewpager>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
FirstFragment.cs

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;

namespace ViewPagerDemo
{
public class FirstFragment : Fragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.first_frag, container, false);

TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragFirst);
tv.Text = Arguments.GetString("msg");

return v;
}

public static FirstFragment newInstance(string text)
{

FirstFragment f = new FirstFragment();
Bundle b = new Bundle();
b.PutString("msg", text);

f.Arguments = b;

return f;
}
}
}

first_frag.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:removed="@android:color/holo_orange_dark">
<textview>
android:id="@+id/tvFragFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="26dp"
android:text="TextView" />


SecondFragment.cs

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;

namespace ViewPagerDemo
{
public class SecondFragment : Fragment
{

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.second_frag, container, false);

TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragSecond);
tv.Text = Arguments.GetString("msg");

return v;
}

public static SecondFragment newInstance(string text)
{

SecondFragment f = new SecondFragment();
Bundle b = new Bundle();
b.PutString("msg", text);

f.Arguments = b;

return f;
}
}
}

second_frag.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:removed="@android:color/holo_green_dark">
<textview>
android:id="@+id/tvFragSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="26dp"
android:text="TextView" />


ThirdFragment.cs

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;

namespace ViewPagerDemo
{
public class ThirdFragment : Fragment
{

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.Inflate(Resource.Layout.third_frag, container, false);

TextView tv = (TextView) v.FindViewById(Resource.Id.tvFragThird);
tv.Text = Arguments.GetString("msg");

return v;
}

public static ThirdFragment newInstance(string text)
{

ThirdFragment f = new ThirdFragment();
Bundle b = new Bundle();
b.PutString("msg", text);

f.Arguments = b;

return f;
}
}
}

third_frag.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:removed="@android:color/holo_red_light">
<textview>
android:id="@+id/tvFragThird"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="26dp"
android:text="TextView" />



AND IT IS SHOWING ERROR IN MAINACTIVITY
AND THE ERROR IS "ViewPagerDemo.MainActivity.MyPageAdapter does not implement inherited abstract member Android.Support.V4.App.FragmentPagerAdapter" so Plzz Let Me Out Of this Problem.
Posted
Updated 28-Apr-14 20:31pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900