Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Load more items without button click

$
0
0

Dears,

I am implementing load more items to listview without a button.

My code:

 public partial class DashBoardPage : ContentPage
  {
    ObservableCollection<string> Items;
    bool isLoading;

    public DashBoardPage()
    {
        InitializeComponent();

        Items = new ObservableCollection<string>();
        var listview = new ListView();

        listview.ItemsSource = Items;
        listview.ItemAppearing += (sender, e) =>
        {
            if (isLoading || Items.Count == 0)
                return;

            //hit bottom!
            if (e.Item.ToString() == Items[Items.Count - 1])
            {
                LoadItems();
            }
        };
        LoadItems();
    }

    public async void LoadItems()
    {
        isLoading = true;
        HttpClient client = new HttpClient();
        var response = await client.GetAsync("My Url");
        string tweetJson = await response.Content.ReadAsStringAsync();

        UserTweetResponse userTweetResponse = new UserTweetResponse();
        if (tweetJson != "")
        {
            userTweetResponse = JsonConvert.DeserializeObject<UserTweetResponse>(tweetJson.ToString());
        }
        ListView1.ItemsSource = userTweetResponse.userTweetsList;
        isLoading = false;
    }
}

I refer the following link and confused with the for loop inside LoadItems():
https://montemagno.com/load-more-items-at-end-of-listview-in/
for (int i = 0; i < 20; i++)
{
Items.Add (string.Format("Item {0}", Items.Count));
}
In my case I am using itemSource property to bind the response to list view.
How can I fix this?
Thanks in advance :)


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>