起動時にアダプターをリストビューに設定しようとして、モノドロイドで遊んでいます。私は画面上にたくさんのコントロールを持っています。私がやろうとしているのは、ボタンをクリックすると項目がリストビューに入るということです。
デバッガーからエラーは発生しません。「残念ながら Application1 が停止しました」というメッセージが表示されるだけで、何が間違っているのかを突き止めるのが難しくなります。
これが私のコードです:
public class Activity1 : Activity
{
List<string> items = new List<string>();
ArrayAdapter<string> adaptor;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
int i = 0;
items.Add("Hello world");
adaptor = new ArrayAdapter<string>(this,
Resource.Id.listView1,
items);
Button button = FindViewById<Button>(Resource.Id.button1);
ListView listView = FindViewById<ListView>(Resource.Id.listView1);
listView.SetAdapter(adaptor);
button.Click += delegate
{
items.Add("Hello " + ++i);
adaptor.NotifyDataSetChanged();
};
}
}
コメントすると、次のようなデバイス ログが見つかりました。
android.content.res.Resources$NotFoundException: Resource ID #0x7f050003 type #0x12 is not valid
これは、Resource.Designer.cs のリストビューの ID です。
public const int listView1 = 2131034115;
リストビューは次のように宣言されます。
<ListView
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="wrap_content"
p1:layout_height="fill_parent"
p1:id="@+id/listView1"
p1:layout_marginBottom="70dp" />