這是main.axml文件。Resource.Id不能在Xamarin中工作
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myListView" />
</LinearLayout>`
而這正是MainActivity.cs文件:
保護覆蓋無效的OnCreate(束束) { base.OnCreate(束);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
Glop = new List<string>();
Glop.Add("Tom");
Glop.Add("Dick");
Glop.Add("Harry");
Name = FindViewById<ListView>(Resource.Id.myListView);
}
我想在Xamarin Android中創建一個Listview。
我已經改變了Android ID到myListView,也試圖重建應用程序,但它仍然顯示爲錯誤。我現在應該怎麼做 ?
清理並重建您的項目。然後它應該重新生成'Resources.designer.cs'文件,該文件應該包含新的'Id'定義。 –