刷新时缺少列表视图详细信息

时间:2019-07-09 03:26:29

标签: c# listview xamarin xamarin.forms xamarin.android

我有一个列出所有客户的列表。在搜索框中输入内容时,我会刷新列表。我的问题是,当我输入某些内容时,列表变得不稳定,这意味着列表的某些部分缺少详细信息,例如客户名称。

我会告诉你我的意思。

加载后的列表如下:

图片:

Image 1 这是我轻按该项时列表的样子(当我轻按一项时刷新列表)或搜索内容:

Image 2

现在这是我列出页面的代码。

这是我的XAML代码:

<ListView SeparatorVisibility="Default" x:Name="lstActivity" ItemSelected="LstActivity_ItemSelected" ItemTapped="LstActivity_ItemTapped" HasUnevenRows="True">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <Frame StyleClass="lstframe" CornerRadius="0" BorderColor="Transparent" HasShadow="False">
                                        <StackLayout StyleClass="lstContainer" VerticalOptions="CenterAndExpand">
                                            <Grid>
                                                <Label VerticalTextAlignment="Center" StyleClass="lstActivityName" VerticalOptions="Center" Grid.Row="0" Grid.Column="0" Text="{Binding ActivityDescription}">
                                                    <Label.FontFamily>
                                                        <OnPlatform x:TypeArguments="x:String">
                                                            <On Platform="Android" Value="SFProDisplay-Regular.ttf#SFProDisplay-Regular"/>
                                                        </OnPlatform>
                                                    </Label.FontFamily>
                                                </Label>
                                                <Switch VerticalOptions="Center" Grid.Row="0" Grid.Column="1" IsEnabled="False" IsToggled="{Binding Selected}" />
                                            </Grid>
                                        </StackLayout>
                                    </Frame>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

这是我的XAML.cs代码:

public void List_Activity()
    {
        try
        {
            var keyword = entSearchActivity.Text;

            if (String.IsNullOrEmpty(keyword))
            {
                var query = DefaultSettings.conn.QueryAsync<ActivityTable>("SELECT ActivityDescription, ActivityID, Selected FROM tblActivity ORDER BY ActivityDescription LIMIT 20");
                var resultCount = query.Result.Count;

                if (resultCount > 0)
                {
                    lstActivity.IsVisible = true;
                    result = query.Result;
                    lstActivity.ItemsSource = result;
                }
                else
                {
                    lstActivity.IsVisible = false;
                }
            }
            else
            {
                var query = DefaultSettings.conn.QueryAsync<ActivityTable>("SELECT ActivityDescription, ActivityID, Selected FROM tblActivity WHERE ActivityDescription LIKE '%" + keyword +"%' ORDER BY ActivityDescription LIMIT 20");
                var resultCount = query.Result.Count;

                if (resultCount > 0)
                {
                    lstActivity.IsVisible = true;
                    result = query.Result;
                    lstActivity.ItemsSource = result;
                }
                else
                {
                    lstActivity.IsVisible = false;
                }
            }
        }
        catch (Exception ex)
        {
            Crashes.TrackError(ex);
        }
    }

这是我的ActivityTable.cs:

[Table("tblActivity")]
public class ActivityTable
{
    [PrimaryKey]
    public string ActivityID { get; set; }
    public string ActivityDescription { get; set; }
    public string RecordLog { get; set; }
    public DateTime LastSync { get; set; }
    public DateTime LastUpdated { get; set; }
    public int Deleted { get; set; }
    public int Checked { get; set; }
    public int Finished { get; set; }
    public bool Selected { get; set; }
}

我的问题是:

  1. 这是什么原因?
  2. 将来如何避免这种情况?

0 个答案:

没有答案