Dear All,
I would like to attach map object into my sliding tabs. first tab is detail information, and the second tab is map object which is refer to detail information address. Since slidingtab use fragment to implement it and to load map object use fragment also, I got error when I'd like to setup the Map.
"An object reference is required for the non-static field, method, or property 'Activity.FragmentManager'".
Here's is my code.
Please advise how can I implement my map load into my second tab.
Best Regards,
Afin
public class ContactInfoFragment : Fragment
{
private slidingtabscrollview mslidingtabscrollview;
private ViewPager mViewPager;
private Guid crmcontactid;
public ContactInfoFragment(Guid contactId)
{
crmcontactid = contactId;
}
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
// return inflater.Inflate(Resource.Layout.YourFragment, container, false);
return inflater.Inflate(Resource.Layout.ContactDetailFragment, container, false);
}
public override void OnViewCreated(View view, Bundle savedInstanceState)
{
setupViewPager(mViewPager, view);
}
void setupViewPager(ViewPager viewPager, View view)
{
mslidingtabscrollview = view.FindViewById<slidingtabscrollview>(Resource.Id.contact_slidingtabs);
mViewPager = view.FindViewById<ViewPager>(Resource.Id.contact_viewpager);
mViewPager.Adapter = new ContactPageAdapter(crmcontactid);
mslidingtabscrollview.ViewPager = mViewPager;
}
public class ContactPageAdapter : PagerAdapter, IOnMapReadyCallback
{
List<string> items = new List<string>();
private Guid crmcontactid;
private GoogleMap mMap;
private string contactaddress;
private string contactfullname;
private LatLng globalposition;
public ContactPageAdapter(Guid parmcrmcontactid) : base()
{
crmcontactid = parmcrmcontactid;
items.Add("Contact Info");
items.Add("Contact Map");
items.Add("Contact Tasks");
}
public override int Count
{
get
{
return items.Count;
}
}
public override bool IsViewFromObject(View view, Java.Lang.Object objectValue)
{
return view == objectValue;
}
public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
{
//TextView texttitle = view.FindViewById<TextView>(Resource.Id.item_title);
View view;
contactinfoadapter contactinfo;
contactmapadapter contactmap;
int pos = position + 1;
if (pos == 1)
{
view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.ContactInfoContentFragment, container, false);
container.AddView(view);
contactinfo = contactinfoadapter.getInstance_contactinfoadapter();
contactinfo.assignvaluetocontactinfo(crmcontactid, view);
}
else if (pos == 2)
{
view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.ContactMapContentFragment, container, false);
container.AddView(view);
//TextView texttitle = view.FindViewById<TextView>(Resource.Id.item_title);
//texttitle.Text = "Map";
contactinfo = contactinfoadapter.getInstance_contactinfoadapter();
contactaddress = contactinfo.contactaddress;
contactfullname = contactinfo.contactfullname;
SetupMap();
}
else
{
view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.PagerItem, container, false);
container.AddView(view);
TextView texttitle = view.FindViewById<TextView>(Resource.Id.item_title);
texttitle.Text = "contact Task List";
}
return view;
}
private void SetupMap()
{
if (mMap == null)
{
Android.App.Activity.FragmentManager.FindFragmentById<MapFragment>(Resource.Id.contactmap_mapinfo).GetMapAsync(this);
}
}
public void OnMapReady(GoogleMap googleMap)
{
contactmapadapter cmapadapter = new contactmapadapter(contactaddress, contactfullname);
cmapadapter.GetLocationFromAddress(contactaddress);
mMap = googleMap;
//LatLng latlng = new LatLng(40.776408, -73.970755);
MarkerOptions options = new MarkerOptions()
.SetPosition(globalposition)
.SetTitle(contactfullname)
.SetSnippet(contactaddress.Substring(1, 20) + "...");
mMap.AddMarker(options);
}
public string GetHeaderTitle (int position)
{
return items[position];
}
public override void DestroyItem(ViewGroup container, int position, Java.Lang.Object objectValue)
{
container.RemoveView((View)objectValue);
}
}