PDA

View Full Version : FragmentTabHost ??? (xamarin) C# VS2012



jojoba2010
پنج شنبه 16 مرداد 1393, 13:14 عصر
با سلام
در Xamarin برای FragmentActivity برای FragmentTabHost می خواستم ؟
من از https://components.xamarin.com/view/xamandroidsupportv4-18 استفاده کردمبا خطای زیر مواجه می شوم
Error 1 The type 'Android.Runtime.IJavaObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. C:\Users\naeim\Documents\xamandroidsupportv4-18-20.0.0.3\xamandroidsupportv4-18-20.0.0.3\samples\AndroidSupportSample\AndroidSuppo rtSample\TitlesFragment.cs 11 15 AndroidSupportSample

راهنمایی کنید
با تشکر

jojoba2010
جمعه 17 مرداد 1393, 16:19 عصر
کسی نبود راهنمایی کنه؟

jojoba2010
شنبه 18 مرداد 1393, 02:31 صبح
از موارد زیر استفاده کردم با زهم خطا می دهد


1.Xamarin.Android.Support.v4 via :Install-Package Xamarin.Android.Support.v4 -Version 20.0.0
2.android-support-v4.jar ( as AndroidJavaLibrary) --- with 634 kb
3.using Android.Support.V4.App;
4. public class Activity1 : FragmentActivity <----- i get error in Activity1
{ //my codes }
خطای زیر می دهد
The type 'Android.App.Activity' is defined in an assembly that is not referenced. You must add a reference to assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'.

samanmari
شنبه 18 مرداد 1393, 08:41 صبح
@jojoba2010
رو چه mode این خطارو میده؟
Debug or Release?

jojoba2010
شنبه 18 مرداد 1393, 17:58 عصر
راه حل:
می بایست ورژن mono.android.4.10 تغییر می دادم

jojoba2010
دوشنبه 17 شهریور 1393, 08:02 صبح
من از fragmenttabhost در xamarin C#‎‎‎‎‎‎‎‎‎‎‎ VS2013 استفاده می کنم(برای اینکه برنامه از نسخه 2.2 به بالا را ساپورت کنه)
که با خطا مواجه می شوم:
Activity 2.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;
using Android.Content.PM;
using Android.Support.V4.App;


namespace ANRestaurant.Forms
{
[Activity(Label = "ANRestaurant", MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Portrait)]


public class Activity2 : FragmentActivity
{
FragmentTabHost mTabHost;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);


SetContentView(Resource.Layout.activity_main);
try
{
mTabHost = FindViewById<FragmentTabHost>(Resource.Id.tabhostN);
Intent intent;
intent = new Intent(this, typeof(Fragment1));
intent.AddFlags(ActivityFlags.NewTask);
//mTabHost.Setup(this, SupportFragmentManager, Resource.Id.tabFrameLayout);


TabHost.TabSpec spec;
spec = mTabHost.NewTabSpec("artists");
spec.SetIndicator("Artists", Resources.GetDrawable(Resource.Drawable.tab_icon1) );
spec.SetContent(intent);
mTabHost.AddTab(spec); ======>در این قسمت خطا می دهد
//mTabHost.AddTab(
// mTabHost.NewTabSpec("tab2").SetIndicator("Tab 2", null),
// intent, null);
//mTabHost.addTab(
// mTabHost.newTabSpec("tab2").setIndicator("Tab 2", null),
// FragmentTab.class, null);
//mTabHost.addTab(
// mTabHost.newTabSpec("tab3").setIndicator("Tab 3", null),
// FragmentTab.class, null);
}
catch (Exception ex)
{


}
}
}
}



activity_main.axml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhostN"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@+id/tabFrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>



Fragment1.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.Util;
using Android.Views;
using Android.Widget;


namespace ANRestaurant.Forms
{
public class Fragment1 : Fragment
{



public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);


// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate(Resource.Layout.fragment1, container, false);
return view;
//return base.OnCreateView(inflater, container, savedInstanceState);
}
}
}


fragment1.axml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AA1111">
<TextView
android:id="@+id/txtF"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="This is Tab 1"
android:textSize="20sp"
android:textColor="#dddddd"
android:layout_centerInParent="true" />
</RelativeLayout>




پیغام خطا که می دهد :



{Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00063] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/98634deb/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:507
at Android.Widget.TabHost.AddTab (Android.Widget.TabSpec tabSpec) [0x00043] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/98634deb/source/monodroid/src/Mono.Android/platforms/android-12/src/generated/Android.Widget.TabHost.cs:801
at ANRestaurant.Forms.Activity2.OnCreate (Android.OS.Bundle bundle) [0x00079] in e:\Home\Herman resturant Android\Source\ANRestaurant\ANRestaurant\Forms\Act ivity2.cs:39
--- End of managed exception stack trace ---
java.lang.NullPointerException
at android.widget.TabHost.addTab(TabHost.java:236)
at anrestaurant.forms.Activity2.n_onCreate(Native Method)
at anrestaurant.forms.Activity2.onCreate(Activity2.ja va:28)
at android.app.Activity.performCreate(Activity.java:5 104)
at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThre ad.java:141)
at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99 )
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.jav a:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:560)
at dalvik.system.NativeStart.main(Native Method)
}

jojoba2010
دوشنبه 17 شهریور 1393, 13:07 عصر
با سلام

کسی نیست که بتواند ؟

بازهم تشکر

jojoba2010
سه شنبه 18 شهریور 1393, 07:38 صبح
سلام
کسی نیست؟

jojoba2010
سه شنبه 18 شهریور 1393, 17:20 عصر
مشکل برطرف شد:
می بایست کدی که خطا می دهد را به شکل زیر تغییر دهیم :


mTabHost.Setup(this, SupportFragmentManager, Resource.Id.tabFrameLayout);
mTabHost.AddTab(spec, Java.Lang.Class.FromType(typeof(Fragment1)), null);