我有一個Mono for Android項目,可以使用以下代碼成功編譯和運行。然而,複製/粘貼到我正在處理的較新項目中會導致編譯器錯誤,指示:[appnamespace] .Android.Resource.Layout不包含'SimpleListItem2'的定義。如何讓谷歌在我的Mono for Android項目中提供Android.Resource.Layout引用
如果我試圖訪問我定義的xml資源佈局,但我想要訪問Google提供的默認列表,特別是'SimpleListItem2',我期望這個錯誤。有什麼我需要做的讓編譯器識別默認佈局?謝謝!
public override View GetView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null) {
LayoutInflater li = (LayoutInflater)this.Context.GetSystemService(Context.LayoutInflaterService);
v = li.Inflate(Android.Resource.Layout.SimpleListItem2, null);
}
TextView tt = (TextView)v.FindViewById(Android.Resource.Id.Text1);
if (tt != null) { tt.Text = string.Format("{0}, {1}", this.LastName, this.FirstName); }
return v;
}
基本上,我正在尋找能夠訪問在Mono.Android組裝這些佈局中,Android.Resource.Layout命名空間下:
ActivityListItem
BrowserLInkContextHeader
ExpandableListContent
PreferenceCategory
SelectDialogItem
SelectDialogMultiChoice
SelectDialogSingleChoice
SimpleDropDownItem1Line
SimpleExpandableListItem1
SimpleExpandableListItem2
SimpleGalleryItem
SimpleListItem1
SimpleListItem2
SimpleListItemChecked
SimpleListItemMultipleChoice
SimpleListItemSingleChoice
SimpleListItemDropDownItem
SimpleSpinnerItem
TestListItem
TwoLineListItem
同樣在這裏效力。你提交了一個錯誤或什麼? –
確保沒有其他項目(共享/庫)在其名稱空間中使用android。例如,我使用XYZ.Common.Android作爲通用庫的名稱... OOOOPS。 –
我沒有提交錯誤,因爲它似乎是.NET編譯器/預處理器的有效行爲。編譯器將基於命名空間假定範圍。如果項目要求在名稱空間中使用「Android」,則可以通過完全限定Google Android SDK中所有對象的名稱空間來克服編譯器異常。 – benhorgen