Screenprint.我正在关注this练习“Xamarin Android教程2创建ListView”。这是我的代码:
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
namespace ListViewTutorial
{
[Activity(Label = "ListViewTutorial", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
private List<string> mItems; // 1 Create a list
private ListView mListView; // 3 Get the list view
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
mListView = FindViewById<ListView>(Resource.Id.myListView); // 4 Get the reference to the ListView
mItems = new List<String>(); // 2 Instantiate the list and populate it
mItems.Add("Bob");
mItems.Add("Tom");
mItems.Add("Jim");
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, mItems); // 5 Instantiate the adapter
mListView.Adapter = adapter; // 6
}
}
}
这是我的Main.axml文件:
<?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>
问题是我的ListView没有显示任何内容。我哪里错了?我相信我的代码与视频代码相同。