-2
我想填充列表视图。以下是代码。我得到空指针异常。在调试时,我发现mListView为空。我不确定为什么即使列表正确初始化,mListview也是null。空指针虽然小部件被正确初始化
public class MainActivity : Activity
{
private IndexableListView mListView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
List<string> mItems = new List<string>();
mItems.Add("Diary of a Wimpy Kid 6: Cabin Fever");
mItems.Add("Steve Jobs");
mItems.Add("Inheritance (The Inheritance Cycle)");
ContentAdapter adapter = new ContentAdapter(this, Android.Resource.Layout.SimpleListItem1, mItems);
mListView = (IndexableListView) FindViewById<ListView>(Resource.Id.listview);
mListView.Adapter = adapter;
上面的代码中我设置适配器的最后一行 - 在那里mListview是空的,并给我例外。任何帮助深表感谢。 PS:上面的代码是用于Xamarin
如果你有一个* listview *作为id的* IndexableListView *标签,请检查你的* Main.xml *。 – Rami
你能给我们XML吗? –