c# - Monodroid ListView更新问题

标签 c# android listview xamarin.android

刚刚开始使用 Monodroid,目前正在开发 ListView。 我将一个列表添加到 ArrayAdapter 中,并且我可以正确地看到前两项。但是,当我向列表添加第三个元素时, ListView 不会更新。即使我调用notifyDataSetChanged()。

private ArrayAdapter<string> la;
private ListView list;
private List<String> dayData = new List<String>();

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            this.SetContentView(Resource.Layout.TestLayout);


            dayData.Add(" Test");
            dayData.Add(" Test2"); // Theese two elements shows up fine

            list = this.FindViewById<ListView>(Resource.Id.menuList);
            la = new ArrayAdapter<string>(this, Resource.Layout.list_item, dayData);
            list.Adapter = la;
            list.TextFilterEnabled = true;

            dayData.Add(" Test3"); // This one is not shown
            la.NotifyDataSetChanged();


        } // OnCreate

关于我错过了什么的任何线索吗?

最佳答案

我自己在另一个论坛找到了解决方案。不知何故,ArrayAdapter 在使用列表时不会注意到列表的更改。而是使用 Android.Runtime.JavaList。

您可以在这里找到讨论:http://mono-for-android.1047100.n5.nabble.com/Update-ListView-when-dataset-changes-td4757874.html

就像魅力一样! :)

关于c# - Monodroid ListView更新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9228410/

相关文章:

c# - TransactionScope 而不是使用锁

c# - 硬币数量有限的最小硬币找零问题

c# - 在 C# 应用程序中调用 C++ DLL 函数时如何修复从上下文加载错误

c# - 在 WPF 窗口中捕获 CMD 的输出

java - 使用 java (android) 在 php 中动态更改 mysql 查询

android - Android 本身不支持 HEVC (H.265)?

android - 使用 CORBA 混淆 Android 应用程序

Android ListView 向右/向左滑动,如通话记录

android - ListView 适配器中的图像

Android/ListView : Select first item after loading datas