2014-09-30 62 views
0

我試圖使用片段創建Tabs嘗試在Xamarin上創建片段時獲取Android.Content.Res.Resources + NotFoundException

這是從我的活動代碼:

 #region Send Data To Fragment 
     int productID = Intent.GetIntExtra("ProductID", -1); 
     Bundle detailsBundle = new Bundle(); 
     detailsBundle.PutInt("ID", productID); 
     #endregion 

     #region Tabs 
     ActionBar.Tab tab = ActionBar.NewTab(); 
     tab.SetText("Details"); 
     tab.TabSelected += (sender, args) => { 
      var detailsFragment = new DetailsFragment(); 
      detailsFragment.Arguments = detailsBundle; 
      var ft = FragmentManager.BeginTransaction(); 
      ft.Add(Resource.Id.fragmentConteiner, detailsFragment); 
      ft.Commit(); 
     }; 
     ActionBar.AddTab(tab); 
     //Here Comes another Tab... 

我不前的SetContentView

忘記ActionBar.NavigationMode = ActionBarNavigationMode.Tabs這是我的片段類:

public class DetailsFragment : Fragment { 
    TextView _name; 
    TextView _manufacturer; 
    TextView _price; 
    ImageView _image; 
    Product _product; 

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View view = inflater.Inflate(PhoneCatalog.Resource.Id.fragmentConteiner, container,false); //this is where Exception is thrown saying "Resource ID #0x7f070009 type #0x12 is not valid" 

     _name = view.FindViewById<TextView>(Resource.Id.detailsTextName); 
     _manufacturer = view.FindViewById<TextView>(Resource.Id.detailsTextManufacturer); 
     _price = view.FindViewById<TextView>(Resource.Id.detailsTextPrice); 
     _product = ProductData.Service.GetProducts(this.Arguments.GetInt("ID")); 

     UpdateUI(); 
     return view; 
    } 

    private void UpdateUI() { 
     _name.Text = _product.Name; 
     _manufacturer.Text = _product.Manufacturer; 
     _price.Text = Convert.ToString(_product.Price); 
    } 
} 

這就是我獲取OnCreateView參數 http://i.imgur.com/pp6ySHn.png

,這是我的佈局xml文件在那裏我有FrameLayout

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:p1="http://schemas.android.com/apk/res/android" 
    p1:minWidth="25px" 
    p1:minHeight="25px" 
    p1:layout_width="match_parent" 
    p1:layout_height="match_parent" 
    p1:id="@+id/detailsScrollView"> 
    <FrameLayout 
     p1:minWidth="25px" 
     p1:minHeight="25px" 
     p1:layout_width="match_parent" 
     p1:layout_height="match_parent" 
     p1:id="@+id/fragmentConteiner"> 
     <RelativeLayout 
      p1:minWidth="25px" 
      p1:minHeight="25px" 
      p1:layout_width="match_parent"a 
      p1:layout_height="match_parent" 
      p1:id="@+id/detailsRelativeLayout"> 
      <TextView 
       p1:text="Text" 
       p1:layout_width="wrap_content" 
       p1:layout_height="wrap_content" 
       p1:id="@+id/detailsTextName" 
       p1:padding="5dp" 
       p1:textSize="22sp" 
       p1:textStyle="bold" /> 
      <ImageView 
       p1:src="@android:drawable/ic_menu_gallery" 
       p1:layout_width="match_parent" 
       p1:layout_height="344.5dp" 
       p1:layout_below="@id/detailsTextName" 
       p1:id="@+id/detailsImageView" /> 
      <TextView 
       p1:text="Details" 
       p1:textAppearance="?android:attr/textAppearanceLarge" 
       p1:layout_width="wrap_content" 
       p1:layout_height="wrap_content" 
       p1:layout_below="@id/detailsImageView" 
       p1:id="@+id/detailsTextView" 
       p1:textStyle="bold" 
       p1:padding="5dp" /> 
      <TextView 
       p1:text="Manufacturer" 
       p1:textAppearance="?android:attr/textAppearanceMedium" 
       p1:layout_width="wrap_content" 
       p1:layout_height="wrap_content" 
       p1:layout_below="@id/detailsTextView" 
       p1:id="@+id/detailsTextView1" 
       p1:padding="5dp" /> 
      <TextView 
       p1:text="Price" 
       p1:textAppearance="?android:attr/textAppearanceMedium" 
       p1:layout_width="wrap_content" 
       p1:layout_height="wrap_content" 
       p1:layout_below="@id/detailsTextView1" 
       p1:id="@+id/textView1" 
       p1:padding="5dp" /> 
      <TextView 
       p1:text="Text" 
       p1:layout_width="match_parent" 
       p1:layout_height="32.6dp" 
       p1:layout_toRightOf="@id/detailsTextView1" 
       p1:id="@+id/detailsTextManufacturer" 
       p1:layout_below="@id/detailsTextView" 
       p1:textSize="20sp" 
       p1:padding="5dp" /> 
      <TextView 
       p1:text="Text" 
       p1:layout_width="wrap_content" 
       p1:layout_height="wrap_content" 
       p1:layout_below="@id/detailsTextView1" 
       p1:id="@+id/detailsTextPrice" 
       p1:layout_toRightOf="@id/textView1" 
       p1:padding="5dp" 
       p1:textSize="20sp" /> 
     </RelativeLayout> 
    </FrameLayout> 
</ScrollView> 

任何想法我做錯了嗎?也許我有錯誤的地方或東西<FrameLayout></FrameLayout>

回答

0

好的,修好了。我想我傳遞錯誤的參數inflater.Inflate方法

ProductDetails佈局XML,我必須FrameLayour(上面貼)我只留下了這一點:

<ScrollView xmlns:p1="http://schemas.android.com/apk/res/android" 
p1:minWidth="25px" 
p1:minHeight="25px" 
p1:layout_width="match_parent" 
p1:layout_height="match_parent" 
p1:id="@+id/detailsScrollView"> 
<FrameLayout 
    p1:minWidth="25px" 
    p1:minHeight="25px" 
    p1:layout_width="match_parent" 
    p1:layout_height="match_parent" 
    p1:id="@+id/fragmentConteiner" /> 

然後創建新的佈局文件ProductDetailsFragment和移動休息的XML代碼在這裏:

<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android" 
p1:minWidth="25px" 
p1:minHeight="25px" 
p1:layout_width="match_parent" 
p1:layout_height="match_parent" 
p1:id="@+id/detailsRelativeLayout"> 
<TextView 
    p1:text="Text" 
    p1:layout_width="wrap_content" 
    p1:layout_height="wrap_content" 
    p1:id="@+id/detailsTextName" 
    p1:padding="5dp" 
    p1:textSize="22sp" 
    p1:textStyle="bold" /> 
<ImageView 
    p1:src="@android:drawable/ic_menu_gallery" 
    p1:layout_width="match_parent" 
    p1:layout_height="344.5dp" 
    p1:layout_below="@id/detailsTextName" 
    p1:id="@+id/detailsImageView" /> 
<TextView 
    p1:text="Details" 
    p1:textAppearance="?android:attr/textAppearanceLarge" 
    p1:layout_width="wrap_content" 
    p1:layout_height="wrap_content" 
    p1:layout_below="@id/detailsImageView" 
    p1:id="@+id/detailsTextView" 
    p1:textStyle="bold" 
    p1:padding="5dp" /> 
<TextView 
    p1:text="Manufacturer" 
    p1:textAppearance="?android:attr/textAppearanceMedium" 
    p1:layout_width="wrap_content" 
    p1:layout_height="wrap_content" 
    p1:layout_below="@id/detailsTextView" 
    p1:id="@+id/detailsTextView1" 
    p1:padding="5dp" /> 
<TextView 
    p1:text="Price" 
    p1:textAppearance="?android:attr/textAppearanceMedium" 
    p1:layout_width="wrap_content" 
    p1:layout_height="wrap_content" 
    p1:layout_below="@id/detailsTextView1" 
    p1:id="@+id/textView1" 
    p1:padding="5dp" /> 
<TextView 
    p1:text="Text" 
    p1:layout_width="match_parent" 
    p1:layout_height="32.6dp" 
    p1:layout_toRightOf="@id/detailsTextView1" 
    p1:id="@+id/detailsTextManufacturer" 
    p1:layout_below="@id/detailsTextView" 
    p1:textSize="20sp" 
    p1:padding="5dp" /> 
<TextView 
    p1:text="Text" 
    p1:layout_width="wrap_content" 
    p1:layout_height="wrap_content" 
    p1:layout_below="@id/detailsTextView1" 
    p1:id="@+id/detailsTextPrice" 
    p1:layout_toRightOf="@id/textView1" 
    p1:padding="5dp" 
    p1:textSize="20sp" /> 

DetailsFragment類我改變了這個: View view = inflater.Inflate(PhoneCatalog.Resource.Id.fragmentConteiner, container,false); 這樣: View view = inflater.Inflate(PhoneCatalog.Resource.Layout.ProductDetailsFragment, container,false);

相關問題