【问题标题】:How to return processed collection on ListView xamarin如何在 ListView xamarin 上返回已处理的集合
【发布时间】:2021-10-02 17:35:44
【问题描述】:

我想检查 if 语句,并且只想显示在列表视图上检查的这些值。

`  public void MarkerPressed2()
        {
            MessagingCenter.Subscribe<object, IEnumerable<AlertLevelOnClick>>(this, "PinInfo", (sender, arg) =>
            {
                lstLevel2.ItemsSource = arg;

                var listAlert = new List<AlertLevelOnClick>();

                foreach (var item in arg)
                {
                    
                    var currentData = new AlertLevelOnClick() {
                        dateForecastOnClick = item.dateForecastOnClick,
                        levelForecastOnClick = item.levelForecastOnClick

                    };

                    listAlert.Add(currentData);

                   

                    if (item.levelForecastOnClick == 1)
                    {
                        //how to return every rows on arg or on listview lstLevel2.ItemsSource = arg; with checked
                        //item.levelForecastOnClick and item.dateForecastOnClick on the listView like
                        var test = 5;

                    }
                    else if (item.levelForecastOnClick == 2)
                    {
                         //how to return every rows on arg or on listview lstLevel2.ItemsSource = arg; with checked
                        //item.levelForecastOnClick and item.dateForecastOnClick on the listView like 
                    }
                }
            });

           
        }

使用此代码:lstLevel2.ItemsSource = arg; 我填充了列表视图,但我想先检查 levelForecastOnClick == 1 是否只显示值为 1 和他的日期dateForecastOnClick

如何在 lstLevel2.ItemsSource 上返回检查 arg 集合?

【问题讨论】:

    标签: c# xamarin


    【解决方案1】:
    // create an empty list
    var listAlert = new List<AlertLevelOnClick>();
    
    foreach (var item in arg)
    {
       // if an item meets whatever conditions you want to test for
       if (item.levelForecastOnClick == 1 && ...)
       {
          // add it to the list
          listAlert.Add(item);
       }
    }
    
    // assign your filtered list to the ListView ItemsSource             
    lstLevel2.ItemsSource = listAlert;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多